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

Line number overwrite at code block or page level #1909

Open
yongjun21 opened this issue Oct 3, 2019 · 9 comments
Open

Line number overwrite at code block or page level #1909

yongjun21 opened this issue Oct 3, 2019 · 9 comments
Assignees
Labels
contribution welcome Contributions welcome status: community assigned Community assigned type: feature request Request to add a new feature

Comments

@yongjun21
Copy link

Feature request

What problem does this feature solve?

While the markdown.lineNumber config is useful, sometimes we want to overwrite specific code block or pages. For example line number is useful for demo code especially if we want to highlight specific lines. But in other case like typescript definition, we might want to hide the line numbers.

What does the proposed API look like?

Maybe use Front Matter?

How should this be implemented in your opinion?

Are you willing to work on this yourself?

@ulivz
Copy link
Member

ulivz commented Oct 4, 2019

Contribution welcome!

You can pass the frontmatter setting via the 2nd parameter(env ) in the render method in markdown-loader:

} = markdown.render(content, {
loader,
frontmatter: frontmatter.data,
relativePath: path.relative(sourceDir, file).replace(/\\/g, '/')
})

Consuming this env at the internal lineNumbers plugin.

@ulivz ulivz added type: feature request Request to add a new feature contribution welcome Contributions welcome labels Oct 4, 2019
@yongjun21
Copy link
Author

In the meanwhile I'm using a CSS overwrite targeting language-ts specifically

@roeeyn
Copy link
Contributor

roeeyn commented Oct 14, 2019

I'd love to contribute in this feature! ✨ Can I have this assigned?

@kefranabg
Copy link
Collaborator

Sure @roeeyn

@roeeyn
Copy link
Contributor

roeeyn commented Oct 16, 2019

Hey @kefranabg 👋 I'm working on this issue, but I have some doubts. Where may I reach you? Sorry, I'm kind of newbie, but want to help 😄

@roeeyn
Copy link
Contributor

roeeyn commented Oct 17, 2019

So, my very summarized question is: what is the correct way of accessing the frontmatter from the lineNumbers plugin? Also, this will only work if the lineNumbers is set to true in the markdown config. Is that ok? Maybe we could set to true the lineNumbers by default (so the plugin adds to the chain) and only overriding it in the frontmatter. I tried following @ulivz suggestion but I was not able to reach the front matter inside the plugin. It only reaches the inside of the overridden render method.

md.render = (...args) => {
md.$data = {}
md.$data.__data_block = {}
md.$dataBlock = md.$data.__data_block
const html = render.call(md, ...args)
return {
html,
data: md.$data,
dataBlockString: toDataBlockString(md.$dataBlock)
}
}

Any suggestion?

@FichteFoll
Copy link

According to prism's line-numbers plugin, I tried adding a line-numbers class to the code block via markdown-it-attrs, but it seems that this doesn't work for code blocks in vuepress because those are processed separately (and it also uses a separate line numbers plugin).

I would love to do block-specific overrides like the following:

``` {.line-numbers}
text with
line numbers
```

@FichteFoll
Copy link

FichteFoll commented Apr 19, 2020

I considered disabling the built-in highlight plugin (and the others that basically depend on it) in favor of using markdown-it-prism and its plugins directly, but it doesn't appear to be disableable, unfortunately.

There is a separate issue for this already: #1860

Edit: Apparently, some/many prism plugins can't be used without a browser jGleitz/markdown-it-prism#1.

@trapcodeio
Copy link

In the meanwhile I'm using a CSS overwrite targeting language-ts specifically

This actually helped and I recommend it. E.g I don't need line numbers in shell.
Using .styl

.language-shell.line-numbers-mode
  .line-numbers-wrapper
    display none

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome Contributions welcome status: community assigned Community assigned type: feature request Request to add a new feature
Projects
None yet
Development

No branches or pull requests

6 participants