Skip to content

Commit

Permalink
Merge pull request #996 from Fs02/strip-indent-when-embedding-code
Browse files Browse the repository at this point in the history
strip indent when embedding code fragment
  • Loading branch information
anikethsaha authored Jan 11, 2020
2 parents b3eced3 + 7fb50b9 commit 4f48679
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 36 deletions.
64 changes: 30 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"medium-zoom": "^1.0.4",
"opencollective-postinstall": "^2.0.2",
"prismjs": "^1.15.0",
"strip-indent": "^3.0.0",
"tinydate": "^1.0.0",
"tweezer.js": "^1.4.0"
},
Expand Down Expand Up @@ -98,4 +99,4 @@
"collective": {
"url": "https://opencollective.com/docsify"
}
}
}
3 changes: 2 additions & 1 deletion src/core/render/embed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { get } from '../fetch/ajax'
import { merge } from '../util/core'
import stripIndent from 'strip-indent'

const cached = {}

Expand All @@ -23,7 +24,7 @@ function walkFetchEmbed({ embedTokens, compile, fetch }, cb) {
if (token.embed.fragment) {
const fragment = token.embed.fragment
const pattern = new RegExp(`(?:###|\\/\\/\\/)\\s*\\[${fragment}\\]([\\s\\S]*)(?:###|\\/\\/\\/)\\s*\\[${fragment}\\]`)
text = ((text.match(pattern) || [])[1] || '').trim()
text = stripIndent((text.match(pattern) || [])[1] || '').trim()
}

embedToken = compile.lexer(
Expand Down

0 comments on commit 4f48679

Please sign in to comment.