]> luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/markdown.js
Initial commit.
[flow-web.git] / static / highlight / es / languages / markdown.js
1 /*! `markdown` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar = (function () {
3 'use strict';
4
5 /*
6 Language: Markdown
7 Requires: xml.js
8 Author: John Crepezzi <john.crepezzi@gmail.com>
9 Website: https://daringfireball.net/projects/markdown/
10 Category: common, markup
11 */
12
13 function markdown(hljs) {
14 const regex = hljs.regex;
15 const INLINE_HTML = {
16 begin: /<\/?[A-Za-z_]/,
17 end: '>',
18 subLanguage: 'xml',
19 relevance: 0
20 };
21 const HORIZONTAL_RULE = {
22 begin: '^[-\\*]{3,}',
23 end: '$'
24 };
25 const CODE = {
26 className: 'code',
27 variants: [
28 // TODO: fix to allow these to work with sublanguage also
29 { begin: '(`{3,})[^`](.|\\n)*?\\1`*[ ]*' },
30 { begin: '(~{3,})[^~](.|\\n)*?\\1~*[ ]*' },
31 // needed to allow markdown as a sublanguage to work
32 {
33 begin: '```',
34 end: '```+[ ]*$'
35 },
36 {
37 begin: '~~~',
38 end: '~~~+[ ]*$'
39 },
40 { begin: '`.+?`' },
41 {
42 begin: '(?=^( {4}|\\t))',
43 // use contains to gobble up multiple lines to allow the block to be whatever size
44 // but only have a single open/close tag vs one per line
45 contains: [
46 {
47 begin: '^( {4}|\\t)',
48 end: '(\\n)$'
49 }
50 ],
51 relevance: 0
52 }
53 ]
54 };
55 const LIST = {
56 className: 'bullet',
57 begin: '^[ \t]*([*+-]|(\\d+\\.))(?=\\s+)',
58 end: '\\s+',
59 excludeEnd: true
60 };
61 const LINK_REFERENCE = {
62 begin: /^\[[^\n]+\]:/,
63 returnBegin: true,
64 contains: [
65 {
66 className: 'symbol',
67 begin: /\[/,
68 end: /\]/,
69 excludeBegin: true,
70 excludeEnd: true
71 },
72 {
73 className: 'link',
74 begin: /:\s*/,
75 end: /$/,
76 excludeBegin: true
77 }
78 ]
79 };
80 const URL_SCHEME = /[A-Za-z][A-Za-z0-9+.-]*/;
81 const LINK = {
82 variants: [
83 // too much like nested array access in so many languages
84 // to have any real relevance
85 {
86 begin: /\[.+?\]\[.*?\]/,
87 relevance: 0
88 },
89 // popular internet URLs
90 {
91 begin: /\[.+?\]\(((data|javascript|mailto):|(?:http|ftp)s?:\/\/).*?\)/,
92 relevance: 2
93 },
94 {
95 begin: regex.concat(/\[.+?\]\(/, URL_SCHEME, /:\/\/.*?\)/),
96 relevance: 2
97 },
98 // relative urls
99 {
100 begin: /\[.+?\]\([./?&#].*?\)/,
101 relevance: 1
102 },
103 // whatever else, lower relevance (might not be a link at all)
104 {
105 begin: /\[.*?\]\(.*?\)/,
106 relevance: 0
107 }
108 ],
109 returnBegin: true,
110 contains: [
111 {
112 // empty strings for alt or link text
113 match: /\[(?=\])/ },
114 {
115 className: 'string',
116 relevance: 0,
117 begin: '\\[',
118 end: '\\]',
119 excludeBegin: true,
120 returnEnd: true
121 },
122 {
123 className: 'link',
124 relevance: 0,
125 begin: '\\]\\(',
126 end: '\\)',
127 excludeBegin: true,
128 excludeEnd: true
129 },
130 {
131 className: 'symbol',
132 relevance: 0,
133 begin: '\\]\\[',
134 end: '\\]',
135 excludeBegin: true,
136 excludeEnd: true
137 }
138 ]
139 };
140 const BOLD = {
141 className: 'strong',
142 contains: [], // defined later
143 variants: [
144 {
145 begin: /_{2}(?!\s)/,
146 end: /_{2}/
147 },
148 {
149 begin: /\*{2}(?!\s)/,
150 end: /\*{2}/
151 }
152 ]
153 };
154 const ITALIC = {
155 className: 'emphasis',
156 contains: [], // defined later
157 variants: [
158 {
159 begin: /\*(?![*\s])/,
160 end: /\*/
161 },
162 {
163 begin: /_(?![_\s])/,
164 end: /_/,
165 relevance: 0
166 }
167 ]
168 };
169
170 // 3 level deep nesting is not allowed because it would create confusion
171 // in cases like `***testing***` because where we don't know if the last
172 // `***` is starting a new bold/italic or finishing the last one
173 const BOLD_WITHOUT_ITALIC = hljs.inherit(BOLD, { contains: [] });
174 const ITALIC_WITHOUT_BOLD = hljs.inherit(ITALIC, { contains: [] });
175 BOLD.contains.push(ITALIC_WITHOUT_BOLD);
176 ITALIC.contains.push(BOLD_WITHOUT_ITALIC);
177
178 let CONTAINABLE = [
179 INLINE_HTML,
180 LINK
181 ];
182
183 [
184 BOLD,
185 ITALIC,
186 BOLD_WITHOUT_ITALIC,
187 ITALIC_WITHOUT_BOLD
188 ].forEach(m => {
189 m.contains = m.contains.concat(CONTAINABLE);
190 });
191
192 CONTAINABLE = CONTAINABLE.concat(BOLD, ITALIC);
193
194 const HEADER = {
195 className: 'section',
196 variants: [
197 {
198 begin: '^#{1,6}',
199 end: '$',
200 contains: CONTAINABLE
201 },
202 {
203 begin: '(?=^.+?\\n[=-]{2,}$)',
204 contains: [
205 { begin: '^[=-]*$' },
206 {
207 begin: '^',
208 end: "\\n",
209 contains: CONTAINABLE
210 }
211 ]
212 }
213 ]
214 };
215
216 const BLOCKQUOTE = {
217 className: 'quote',
218 begin: '^>\\s+',
219 contains: CONTAINABLE,
220 end: '$'
221 };
222
223 const ENTITY = {
224 //https://spec.commonmark.org/0.31.2/#entity-references
225 scope: 'literal',
226 match: /&([a-zA-Z0-9]+|#[0-9]{1,7}|#[Xx][0-9a-fA-F]{1,6});/
227 };
228
229 return {
230 name: 'Markdown',
231 aliases: [
232 'md',
233 'mkdown',
234 'mkd'
235 ],
236 contains: [
237 HEADER,
238 INLINE_HTML,
239 LIST,
240 BOLD,
241 ITALIC,
242 BLOCKQUOTE,
243 CODE,
244 HORIZONTAL_RULE,
245 LINK,
246 LINK_REFERENCE,
247 ENTITY
248 ]
249 };
250 }
251
252 return markdown;
253
254 })();
255 ;
256 export default hljsGrammar;