@matheusbsbs / matheus-bagliano / commits / 09dad9256a
Fork 0

userdiff: support Markdown

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>

Ash Holland committed May 2, 2020 at 14:15 UTC 09dad9256a32affc4a3bc0cf1fa45d5fa6f51231
5 files changed +29
Documentation/gitattributes.txt
+2
@@ -824,6 +824,8 @@ patterns are available:
824
825 - `java` suitable for source code in the Java language.
826
827 +- `markdown` suitable for Markdown documents.
828 +
829 - `matlab` suitable for source code in the MATLAB and Octave languages.
830
831 - `objc` suitable for source code in the Objective-C language.
t/t4018-diff-funcname.sh
+1
@@ -38,6 +38,7 @@ diffpatterns="
38 golang
39 html
40 java
41 + markdown
42 matlab
43 objc
44 pascal
t/t4018/markdown-heading-indented new
+6
@@ -0,0 +1,6 @@
1 +Indented headings are allowed, as long as the indent is no more than 3 spaces.
2 +
3 + ### RIGHT
4 +
5 +- something
6 +- ChangeMe
t/t4018/markdown-heading-non-headings new
+17
@@ -0,0 +1,17 @@
1 +Headings can be right next to other lines of the file:
2 +# RIGHT
3 +Indents of four or more spaces make a code block:
4 +
5 + # code comment, not heading
6 +
7 +If there's no space after the final hash, it's not a heading:
8 +
9 +#hashtag
10 +
11 +Sequences of more than 6 hashes don't make a heading:
12 +
13 +####### over-enthusiastic heading
14 +
15 +So the detected heading should be right up at the start of this file.
16 +
17 +ChangeMe
userdiff.c
+3
@@ -79,6 +79,9 @@ PATTERNS("java",
79 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?"
80 "|[-+*/<>%&^|=!]="
81 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"),
82 +PATTERNS("markdown",
83 + "^ {0,3}#{1,6}[ \t].*",
84 + "[^<>= \t]+"),
85 PATTERNS("matlab",
86 /*
87 * Octave pattern is mostly the same as matlab, except that '%%%' and