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

Breaks not rendering when using $md.render() #13

Open
Mei152 opened this issue Mar 3, 2018 · 6 comments
Open

Breaks not rendering when using $md.render() #13

Mei152 opened this issue Mar 3, 2018 · 6 comments

Comments

@Mei152
Copy link

Mei152 commented Mar 3, 2018

Hello. Hoping for some direction here about what I might be doing wrong.
I am using the markdownit module to render content produced from the Netlify CMS editor. The markdown-it configuration breaks: true doesn't seem to be honored in the HTML output. I deleted linkify: true just to see if any of the config settings were working, and, indeed, http://bla.com stopped displaying as an anchor, so that at least that is working as expected.

Any idea why \n\n is not showing up as a <br>?
markdown-it docs say:

breaks - false. Set true to convert \n in paragraphs into <br>

Thanks for your help!

nuxt.config.js

 modules: [
    '@nuxtjs/markdownit'
  ],

  // [optional] markdownit options
  // See https://github.com/markdown-it/markdown-it
  markdownit: {
    injected: true,
    preset: 'default',
    linkify: true,
    breaks: true,
    use: [
      'markdown-it-container',
      'markdown-it-attrs'
    ]
  },

stuff.json

{
  "title": "Stuff",
  "date": "2018-03-01T23:59:10.464Z",
  "body": "Some stuff is here\n\n**And a whole bunch more here!**\n\n1. stuff\n2. stuff\n3. and more stuff\nhttp://bla.com"
}

stuff.vue

<template>
  <article>
    <h1>{{ title }}</h1>
    <div v-html="$md.render(body)"></div>
  </article>
</template>

<script>
  export default {
    async asyncData({ params }) {
      let stuff = await import('~/content/stuff.json');
      return stuff;
    }
  };
</script>

HTML output

<div id="__nuxt"><div class="nuxt-progress" style="width:0%;height:2px;background-color:#3B8070;opacity:0;"></div>
  <div id="__layout">
    <div>
      <article>
        <h1>Stuff</h1>
        <div>
          <p>Some stuff is here</p>
          <p><strong>And a whole bunch more here!</strong></p>
          <ol>
            <li>stuff</li>
            <li>stuff</li>
            <li>and more stuff<br>
            <a href="http://bla.com">http://bla.com</a></li>
          </ol>
        </div>
      </article>
    </div>
  </div>
</div>
This question is available on Nuxt.js community (#c115)
@ig1na
Copy link

ig1na commented Nov 19, 2019

Did you find a solution yet ?

@huaiyukhaw
Copy link

Did you have a solution? I fell into the exact same problem.

@huaiyukhaw
Copy link

Adding CSS white-space: pre-line; to the div solves my problem.

@dogrocker
Copy link

I solved this by

add

<div id="editor" v-html="$md.render(content)"></div>

and add global style with

<style>
#editor p {
  padding: 10px;
}
</style>

@pi0 pi0 transferred this issue from nuxt-community/legacy-modules Dec 29, 2020
@cpt-n3mo
Copy link

Also having this problem, even though the padding thing helps, its a nasty work around as it does not allow for multiple line breaks. anyone know how to properly fix this as the break setting does not seem to do anything.

kind regards

@sven-ra
Copy link

sven-ra commented Jan 18, 2022

Any updates on this?
<div id="editor" v-html="$md.render(content)"></div>
I am also getting my content from a cms so white-space: pre-line; won't cut it, since it will create a lot of unnecessary line breaks.

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

6 participants