-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add support to import files as code fence #538
Conversation
lib/markdown/snippet.js
Outdated
@@ -0,0 +1,43 @@ | |||
const fs = require('fs') | |||
|
|||
module.exports = function codeFrame(md, options = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snippet
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, would you please also add the tests for that?
lib/markdown/snippet.js
Outdated
return true | ||
} | ||
|
||
md.block.ruler.before('fence', 'code-frame', parser) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
29978bf
to
b73bdc5
Compare
Final thing, could you also document for this feature? thanks! |
I feel it should support importing given lines from large a file but that can be a different PR. |
Awesome! welcome to open any PRs for good stuffs like this. |
I wish we could do a syntax more inline with markdown and Vue loaders, for example: # My Config
<code src="@/cookbook/minimal/rollup.config.js"></code>
<code src="@/cookbook/minimal/rollup.config.js" start="1" end="10"></code> This is both valid markdown, and benefits include:
|
@octref Looks good to me, but for now there are some restrictions for us to implement above syntax: Since our md's process pipeline is So for the above grammar, we need to implement a simple XML parser at markdown's side which looks too complicated. I just have an idea, which is simple, semantic enough and also offer jump-to-definition:
|
@ulivz That's actually quite a nice idea. I was about to suggest https://github.com/iainc/Markdown-Content-Blocks which would solve the problem of file transcultion in general. One problem is |
@octref's concerns are valid. Let's give this problem another shot. What do we need:
@yyx990803 Any suggestions here?
|
Something like https://github.com/posva/markdown-it-custom-block could be better here. :[code](../somefile.js)
:[code {1,4}](../somefile.js)
:[code js{1,4}](../somefile.js)
:[code js{1,4}](../somefile.js "1-10") <!-- Partial Transclusion --> It would support explicit language, line highlighting and with click jumping editor support. @octref WDYT? |
@znck I like it. but how about this syntax for @[code{1-10} js{1,4}](../somefile.js) It prevent the links from being changed and still offer jump-to-definition. |
I'll send a PR by EOD. |
I think the highlight line syntax need more thought. Can you do things like |
If you have a large file and you want to import only couple of lines. Example importing only script from SFC. |
Well you can also remove other lines in the source file, if they are not relevant. |
Hey, so can anybody tell me if some time in a future we will have possibility to include partially code snippets or it wont be possible for some religion reasons? Write really good documentation which is updating together with code is very important. let's say I have some class and important business method in it. So It would be awesome to tell vuepress include code only (for example) from comment with start-lable to comment with ending label. codeWontBeIncluded();
// tag::snippet-1
myBusinessMethod();
myOtherImportantCode();
// end::snippet-1
otherCodeWontBeIncluded(); so If I will add some more important code in between Guys, please add such possibility, we really needed it Thanks Regards, |
Add rule to import code snippets: