]> git.ipfire.org Git - thirdparty/git.git/commitdiff
userdiff: support Markdown
authorAsh Holland <ash@sorrel.sh>
Sat, 2 May 2020 13:15:43 +0000 (14:15 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 3 May 2020 01:04:12 +0000 (18:04 -0700)
It's typical to find Markdown documentation alongside source code, and
having better context for documentation changes is useful; see also
commit 69f9c87d4 (userdiff: add support for Fountain documents,
2015-07-21).

The pattern is based on the CommonMark specification 0.29, section 4.2
<https://spec.commonmark.org/> but doesn't match empty headings, as
seeing them in a hunk header is unlikely to be useful.

Only ATX headings are supported, as detecting setext headings would
require printing the line before a pattern matches, or matching a
multiline pattern. The word-diff pattern is the same as the pattern for
HTML, because many Markdown parsers accept inline HTML.

Signed-off-by: Ash Holland <ash@sorrel.sh>
Acked-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/gitattributes.txt
t/t4018-diff-funcname.sh
t/t4018/markdown-heading-indented [new file with mode: 0644]
t/t4018/markdown-heading-non-headings [new file with mode: 0644]
userdiff.c

index 508fe713c4cfb1e2126bc96fc201ca2cd49c6222..2d0a03715be65edfc4c8be6ca8f2a959ddde7540 100644 (file)
@@ -824,6 +824,8 @@ patterns are available:
 
 - `java` suitable for source code in the Java language.
 
+- `markdown` suitable for Markdown documents.
+
 - `matlab` suitable for source code in the MATLAB and Octave languages.
 
 - `objc` suitable for source code in the Objective-C language.
index 02255a08bf1718659f9815e37644c07a196ab850..9d077975791c1c002b4a927dfae71de594c8855f 100755 (executable)
@@ -38,6 +38,7 @@ diffpatterns="
        golang
        html
        java
+       markdown
        matlab
        objc
        pascal
diff --git a/t/t4018/markdown-heading-indented b/t/t4018/markdown-heading-indented
new file mode 100644 (file)
index 0000000..1991c2b
--- /dev/null
@@ -0,0 +1,6 @@
+Indented headings are allowed, as long as the indent is no more than 3 spaces.
+
+   ### RIGHT
+
+- something
+- ChangeMe
diff --git a/t/t4018/markdown-heading-non-headings b/t/t4018/markdown-heading-non-headings
new file mode 100644 (file)
index 0000000..c479c1a
--- /dev/null
@@ -0,0 +1,17 @@
+Headings can be right next to other lines of the file:
+# RIGHT
+Indents of four or more spaces make a code block:
+
+    # code comment, not heading
+
+If there's no space after the final hash, it's not a heading:
+
+#hashtag
+
+Sequences of more than 6 hashes don't make a heading:
+
+####### over-enthusiastic heading
+
+So the detected heading should be right up at the start of this file.
+
+ChangeMe
index efbe05e5a5b6f1aa9a6b92365a4f987f6078dc04..069a8284cbb09aa5c141cb4ed87332ec81cbcecd 100644 (file)
@@ -79,6 +79,9 @@ PATTERNS("java",
         "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
         "|[-+*/<>%&^|=!]="
         "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
+PATTERNS("markdown",
+        "^ {0,3}#{1,6}[ \t].*",
+        "[^<>= \t]+"),
 PATTERNS("matlab",
         /*
          * Octave pattern is mostly the same as matlab, except that '%%%' and