Skip to content

Commit e011633

Browse files
committed
fix(markdown): Accept heading without space if gfm set to true
1 parent eb6997f commit e011633

5 files changed

Lines changed: 40 additions & 30 deletions

File tree

demo/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<h1>Loading embed.js in a block</h1>
3434

3535
<div id="block" class="block">
36+
#jgjhgjg
37+
3638
**Pulchritudines** nocere, :heart: tanquam ~~talis~~ hibrida.A falsis, brodium :+1: salvus gabalium.Nunquam
3739
promissio @(iit roorkee) http://iitr.ac.in caesium.Cum rumor https://twitter.com/IGN/status/652941146054881281
3840
peregrinationes https://www.flickr.com/photos/xdjio/226228060/, omnes ususes http://www.sample-videos.com/video/mp4/240/big_buck_bunny_240p_50mb.mp4 https://soundcloud.com/the-bugle/bugle-179-playas-gon-play

dist/embed.min.js

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/embed.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/embed.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/modules/markdown.es6

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
class Markdown {
2-
constructor(output, options) {
3-
if (!window.marked) {
4-
throw new ReferenceError(
5-
`marked.js is not loaded.`
6-
)
7-
}
8-
this.output = output
9-
this.options = options
10-
}
2+
constructor(output, options) {
3+
if (!window.marked) {
4+
throw new ReferenceError(
5+
`marked.js is not loaded.`
6+
)
7+
}
8+
this.output = output
9+
this.options = options
10+
}
11+
12+
process() {
13+
let renderer = new marked.Renderer()
14+
renderer.code = function(text) {
15+
let highlightedCode = window.hljs ? hljs.highlightAuto(text) : {
16+
value: text
17+
}
18+
let language = window.hljs ? highlightedCode.language : ''
19+
let template = `<pre><code class="ejs-code hljs ${language}">${highlightedCode.value}</code></pre>`;
20+
return template
21+
}
22+
renderer.link = (text, title, link) => {
23+
if (text.indexOf('&lt;/a') === -1) return text
24+
if (text.match(/&gt;(.+)&lt;\/a/gi)) {
25+
return `<a href="${RegExp.$1}" rel=${this.options.linkOptions.rel}" target="${this.options.linkOptions.target}" title="${title}">${link}</a>`
26+
}
27+
}
28+
29+
//Fix for heading that should be actually present in marked.js
30+
//if gfm is true the `## Heading` is acceptable but `##Heading` is not
31+
marked.Lexer.rules.gfm.heading = marked.Lexer.rules.normal.heading;
32+
marked.Lexer.rules.tables.heading = marked.Lexer.rules.normal.heading;
1133

12-
process() {
13-
let renderer = new marked.Renderer()
14-
renderer.code = function(text) {
15-
let highlightedCode = window.hljs ? hljs.highlightAuto(text) : {
16-
value: text
17-
}
18-
let language = window.hljs ? highlightedCode.language : ''
19-
let template = `<pre><code class="ejs-code hljs ${language}">${highlightedCode.value}</code></pre>`;
20-
return template
21-
}
22-
renderer.link = (text,title,link) => {
23-
if (text.indexOf('&lt;/a') === -1) return text
24-
if (text.match(/&gt;(.+)&lt;\/a/gi)){
25-
return `<a href="${RegExp.$1}" rel=${this.options.linkOptions.rel}" target="${this.options.linkOptions.target}" title="${title}">${link}</a>`
26-
}
27-
}
2834
renderer.paragraph = (text) => `<p> ${text} </p>` //for font smiley in end.
2935
this.options.markedOptions.renderer = renderer
3036
let output = marked(this.output, this.options.markedOptions)

0 commit comments

Comments
 (0)