]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/markdown.js
1 /*! `markdown` grammar compiled for Highlight.js 11.11.1 */
3 var hljsGrammar
= (function () {
9 Author: John Crepezzi <john.crepezzi@gmail.com>
10 Website: https://daringfireball.net/projects/markdown/
11 Category: common, markup
14 function markdown(hljs
) {
15 const regex
= hljs
.regex
;
17 begin: /<\/?[A-Za-z_]/,
22 const HORIZONTAL_RULE
= {
29 // TODO: fix to allow these to work with sublanguage also
30 { begin: '(`{3,})[^`](.|\\n)*?\\1`*[ ]*' },
31 { begin: '(~{3,})[^~](.|\\n)*?\\1~*[ ]*' },
32 // needed to allow markdown as a sublanguage to work
43 begin: '(?=^( {4}|\\t))',
44 // use contains to gobble up multiple lines to allow the block to be whatever size
45 // but only have a single open/close tag vs one per line
58 begin: '^[ \t]*([*+-]|(\\d+\\.))(?=\\s+)',
62 const LINK_REFERENCE
= {
63 begin: /^\[[^\n]+\]:/,
81 const URL_SCHEME
= /[A-Za-z][A-Za-z0-9+.-]*/;
84 // too much like nested array access in so many languages
85 // to have any real relevance
87 begin: /\[.+?\]\[.*?\]/,
90 // popular internet URLs
92 begin: /\[.+?\]\(((data|javascript|mailto):|(?:http|ftp)s?:\/\/).*?\)/,
96 begin: regex
.concat(/\[.+?\]\(/, URL_SCHEME
, /:\/\/.*?\)/),
101 begin: /\[.+?\]\([./?&#].*?\)/,
104 // whatever else, lower relevance (might not be a link at all)
106 begin: /\[.*?\]\(.*?\)/,
113 // empty strings for alt or link text
143 contains: [], // defined later
150 begin: /\*{2}(?!\s)/,
156 className: 'emphasis',
157 contains: [], // defined later
160 begin: /\*(?![*\s])/,
171 // 3 level deep nesting is not allowed because it would create confusion
172 // in cases like `***testing***` because where we don't know if the last
173 // `***` is starting a new bold/italic or finishing the last one
174 const BOLD_WITHOUT_ITALIC
= hljs
.inherit(BOLD
, { contains: [] });
175 const ITALIC_WITHOUT_BOLD
= hljs
.inherit(ITALIC
, { contains: [] });
176 BOLD
.contains
.push(ITALIC_WITHOUT_BOLD
);
177 ITALIC
.contains
.push(BOLD_WITHOUT_ITALIC
);
190 m
.contains
= m
.contains
.concat(CONTAINABLE
);
193 CONTAINABLE
= CONTAINABLE
.concat(BOLD
, ITALIC
);
196 className: 'section',
201 contains: CONTAINABLE
204 begin: '(?=^.+?\\n[=-]{2,}$)',
206 { begin: '^[=-]*$' },
210 contains: CONTAINABLE
220 contains: CONTAINABLE
,
225 //https://spec.commonmark.org/0.31.2/#entity-references
227 match: /&([a-zA-Z0-9]+|#[0-9]{1,7}|#[Xx][0-9a-fA-F]{1,6});/
257 hljs
.registerLanguage('markdown', hljsGrammar
);