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

[markdown-it] Internal links and nuxt router #14

Open
raphmarot opened this issue Feb 14, 2018 · 3 comments
Open

[markdown-it] Internal links and nuxt router #14

raphmarot opened this issue Feb 14, 2018 · 3 comments

Comments

@raphmarot
Copy link

Hi

I use nuxt with external .md files for the content and markdown-it parser.
Is it a way to catch internal links to use nuxt router instead of the generated regular links?

Thx

This question is available on Nuxt.js community (#c107)
@raphmarot
Copy link
Author

raphmarot commented Feb 14, 2018

Solved thanks ;)
Duplicate of #185

<template>
  <div v-html="content">
  </div>
</template>

<script>
export default {
  props: ['content'],
  mounted() {
    this.addListeners()
  },
  beforeDestroy() {
    this.removeListeners()
  },
  watch: {
    'content': 'contentUpdated'
  },
  methods: {
    navigate(event) {
      const href = event.target.getAttribute('href')
      if (href && href[0] === '/') {
        event.preventDefault()
        this.$router.push(href)
      }
    },
    contentUpdated() {
      this.removeListeners()
      this.$nextTick(() => {
        this.addListeners()
      })
    },
    addListeners() {
      this._links = this.$el.getElementsByTagName('a')
      for (let i = 0; i < this._links.length; i++) {
        this._links[i].addEventListener('click', this.navigate, false)
      }
    },
    removeListeners() {
      for (let i = 0; i < this._links.length; i++) {
        this._links[i].removeEventListener('click', this.navigate, false)
      }
      this._links = []
    }
  }
}
</script>

Should be intergrated in markdown-it module btw.

@raphmarot
Copy link
Author

raphmarot commented Feb 14, 2018

Another problem now.

With nuxt generate the content of the md file is not rendered in html, but in the js file. Is there a way to force the html rendering?

Thanks

@raphmarot
Copy link
Author

raphmarot commented Feb 16, 2018

Bump :)

All pages js are in prefetch in every page's head...

@pi0 pi0 transferred this issue from nuxt-community/legacy-modules Dec 29, 2020
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

1 participant