Git fork

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>

authored by

Ash Holland and committed by
Junio C Hamano
09dad925 e870325e

+29
+2
Documentation/gitattributes.txt
··· 824 824 825 825 - `java` suitable for source code in the Java language. 826 826 827 + - `markdown` suitable for Markdown documents. 828 + 827 829 - `matlab` suitable for source code in the MATLAB and Octave languages. 828 830 829 831 - `objc` suitable for source code in the Objective-C language.
+1
t/t4018-diff-funcname.sh
··· 38 38 golang 39 39 html 40 40 java 41 + markdown 41 42 matlab 42 43 objc 43 44 pascal
+6
t/t4018/markdown-heading-indented
··· 1 + Indented headings are allowed, as long as the indent is no more than 3 spaces. 2 + 3 + ### RIGHT 4 + 5 + - something 6 + - ChangeMe
+17
t/t4018/markdown-heading-non-headings
··· 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
+3
userdiff.c
··· 79 79 "|[-+0-9.e]+[fFlL]?|0[xXbB]?[0-9a-fA-F]+[lL]?" 80 80 "|[-+*/<>%&^|=!]=" 81 81 "|--|\\+\\+|<<=?|>>>?=?|&&|\\|\\|"), 82 + PATTERNS("markdown", 83 + "^ {0,3}#{1,6}[ \t].*", 84 + "[^<>= \t]+"), 82 85 PATTERNS("matlab", 83 86 /* 84 87 * Octave pattern is mostly the same as matlab, except that '%%%' and