Skip to content
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: Enhance code snippets import continuation of #538 #750

Closed
ijpatricio opened this issue Aug 18, 2018 · 10 comments
Closed

Feat: Enhance code snippets import continuation of #538 #750

ijpatricio opened this issue Aug 18, 2018 · 10 comments
Labels
type: feature request Request to add a new feature version: next Planned to do or already included in the next(1.0.0) version

Comments

@ijpatricio
Copy link

Feature request

What problem does this feature solve?

When documenting an existing code project, if we later change some code on that, which is being imported on Vuepress docs, it gets out of sync!

So this Feature Request is extending more functionality on top of #538 (and somewhat similar to #612 but much simpler and more flexibility)

What does the proposed API look like?

Currently we have

import contents from somefile.js, bg highlight line 20, syntax highlight as file extension, i presume

<<< @/../project/somefile.js{20}

Proposition on #538 is

//to extract lines 1-10 from somefile.js, syntax highlight as js, and bg highlight lines 1 and 4

@[code{1-10} js{1,4}](../somefile.js)

That's great, and may continue to exist.

For making more dynamic approach, we could use "text-markers" (that could have * as wildcard :) )

// on somefile.js, 
// extract from first line that contains text 'some text',
// until first line that contains text 'another text'
// syntax highlight as js and bg highlight lines that contain 'myFuncName' or 'return someVar'

@[codesearch{'some text'-'another text'} js{'myFuncName','return someVar'}](../somefile.js)

if possible two more optional arguments (some code ommited for clarity)

// Preserve the line numbering matching the original file
// Means keep numbering 50-60 (like on imported file) instead of 1-11

@[codesearch  (...)     filenum{true}](../somefile.js)
// to the found markers, add padding top and bottom (that could be also negative numbers)
// say 'begin-mark' is line 50, start on 46, and if 'end-marker' is 60, finish on 58

@[codesearch (...)   padding{4, -2}](../somefile.js)

How should this be implemented in your opinion?

Pseudo-algorithm to implement it

find first occurence of 'some text', say this is originalLine=50, keep this as snippetLine=1
find first occurence of 'another text', say originalEndLine=60, snippetEndLine=11

if not both markers found, throw exception
if (originalEndLine - originalLine < 1) throw exception

highlight line with occurrence of `myFuncName()`
highlight line with occurrence of `return someVar`

Are you willing to work on this yourself?**

Yes I am. I will need some guidance with webpack related matters.

I do lots of stuff with VueJS for webapps, with SFC, started renderless components few weeks ago and so on... but webpack related, I don't have significant experience.

Going to clone and yarn link to try out locally, what goes on, try to hack something.

Would love to hear your feedback.

Thanks!

@ulivz ulivz added the type: feature request Request to add a new feature label Aug 20, 2018
@ulivz
Copy link
Member

ulivz commented Aug 20, 2018

Cool, thanks for creating this issue. let's work for that after 1.0.0 release.

@ulivz ulivz added TODO version: next Planned to do or already included in the next(1.0.0) version labels Aug 20, 2018
@ijpatricio
Copy link
Author

Cool, glad you like it. I had some problems on running with local "linked" directory, both with npm and yarn.. Could figure out very well.

Could find the file snippet.js, but need a little guidance to kick off.

So when it's time to do this, let me know!

Thanks!

@ijpatricio
Copy link
Author

@ulivz may I sketch/prototype some examples of usage and expected output?

@colwilson
Copy link

Would it be an idea to allow snippets from the file which displays the snippet? This would mean that demo/howto examples could display the code which was used to create the rendered output without duplication.

@jthegedus
Copy link

Without the terms code fence or fencing or fragment in this thread it was difficult to find, so mentioning it now for other's future searching.

Docsify has an implementation of this as seen https://docsify.js.org/#/embed-files?id=embedded-code-fragments and I wanted to ask if anyone was working on this feature here?

@timaschew
Copy link
Contributor

There is already a plugin: #1336
I've even tested it, it's working.

@jthegedus
Copy link

Too right. Wish it supported external sources like Docsify though!

@kefranabg kefranabg removed the TODO label Aug 12, 2019
@flozero
Copy link
Collaborator

flozero commented Sep 5, 2019

As actually a plugin exist i am closing the issue. We will have a look about implement it in core thank's for your time all

@flozero flozero closed this as completed Sep 5, 2019
@cloydlau
Copy link

It seems that plugin is out of maintenance. I mention it here that there's a mistake in the document of that plugin, it should be

  markdown: {
    plugins: ['markdown-it-vuepress-code-snippet-enhanced'],
  },

instead of

  markdown: {
    config: md => {
      md.use(require('markdown-it-vuepress-code-snippet-enhanced'))
    }
  },

The latter will render @[code](@/docs/code.js) as a link.

And one more thing, I use this plugin for *.md files, which is been rendered as highlighted plain text. So how can I make it render as true markdown?

@iamchriswick
Copy link

@cloydlau I don't think rending the output as a link is the intended function of this plugin. It is suppose to render a code block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request Request to add a new feature version: next Planned to do or already included in the next(1.0.0) version
Projects
None yet
Development

No branches or pull requests

9 participants