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

Any way to pass a css class or ID to an element? #84

Closed
Rui-Santos opened this issue Apr 16, 2018 · 4 comments
Closed

Any way to pass a css class or ID to an element? #84

Rui-Santos opened this issue Apr 16, 2018 · 4 comments

Comments

@Rui-Santos
Copy link

Not really an issue, more of a question, as I couldn't find anything about that. The problem is, I have diferent tables on diferent pages and would like to style them seperately, and it doesn't seem possible, as the only specific ID's I see are in the headings, which don't wrap anything more than the headings. I know I can use HTML and wrap the table in a div or something, but was avoiding to use it, as I prefer to keep the pages markdown only.

@yyx990803
Copy link
Member

The only way I can think of is registering a custom container (with https://vuepress.vuejs.org/config/#markdown-config + https://github.com/markdown-it/markdown-it-container) so you can wrap your table inside something:

::: wrapper id-of-the-table
// normal markdown table
:::

@eyleron
Copy link

eyleron commented Apr 27, 2018

Could someone add to their own instance markdown-it-attrs?

Input:

# header {.style-me}
paragraph {data-toggle=modal}

Output:

<h1 class="style-me">header</h1>
<p data-toggle="modal">paragraph</p>

@mbana
Copy link

mbana commented Sep 16, 2019

Could someone add to their own instance markdown-it-attrs?

Input:

# header {.style-me}
paragraph {data-toggle=modal}

Output:

<h1 class="style-me">header</h1>
<p data-toggle="modal">paragraph</p>

Have you actually tried this with a [[toc]]. I think you will find that {.style-me} gets included in the table of contents.

@elmasry
Copy link

elmasry commented Apr 24, 2022

You can use markdown-it-attrs

$ npm install --save markdown-it-attrs

Include it in config.js

module.exports = {
  markdown: {
    extendMarkdown: md => {
      md.use(require('markdown-it-attrs'), {
        // optional, these are default options
        leftDelimiter: '{',
        rightDelimiter: '}',
        allowedAttributes: []  // empty array = all attributes are allowed
      })
    }
  }
}

Example input:

# header {.style-me}
paragraph {data-toggle=modal}

Output:

<h1 class="style-me">header</h1>
<p data-toggle="modal">paragraph</p>

More info https://www.npmjs.com/package/markdown-it-attrs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants