Code Monkey home page Code Monkey logo

Comments (8)

egoist avatar egoist commented on May 31, 2024

这是因为动态添加的 html string 里的 script 不会被执行,解决办法大概是:

  • 在解析 markdown 之后把 html string 里 script 的内容抽出来然后单独创建一个 script 元素添加到 body 末尾
  • 或者直接 eval/new Function 这个 html string 来执行里面的 script 代码

不过我觉得还是写在单独的 js 文件里比较好,因为动态添加的内容执行 js 之后作用是全局的,因为不会需要重新刷新整个页面,各个页面的 js 可能互相影响,那不如直接写在单独的文件里直接在 index.html 中加载。

from docute.

Molunerfinn avatar Molunerfinn commented on May 31, 2024

比方说我要在某段文本后面加入codepen的演示例子,不支持script标签的话就没有办法演示,大概是这个意思。。

from docute.

egoist avatar egoist commented on May 31, 2024

没考虑到这个 😃 这倒可以支持

from docute.

Molunerfinn avatar Molunerfinn commented on May 31, 2024

:) 嗯嗯,期待~Thanks for your work

from docute.

egoist avatar egoist commented on May 31, 2024

不过 codepen 这些的话它的脚本是类似:

<p data-height="300" data-theme-id="17735" data-slug-hash="GNBzOQ" data-default-tab="js,result" data-user="Gthibaud" data-embed-version="2" data-pen-title="vector field Particle" class="codepen">See the Pen <a href="http://codepen.io/Gthibaud/pen/GNBzOQ/">vector field Particle</a> by Gthibaud (<a href="http://codepen.io/Gthibaud">@Gthibaud</a>) on <a href="http://codepen.io">CodePen</a>.</p>
<script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script>

这样的,反正 script 标签是共用的,你应该把这个 script 标签放到 index.html 里,只在 markdown 里加这段 html 就行了

from docute.

Molunerfinn avatar Molunerfinn commented on May 31, 2024

get

from docute.

egoist avatar egoist commented on May 31, 2024

额,其实可以用户自己实现这个功能了,现在提供了 vue-router 的 API,比如:

docute.router.afterEach((to, from, next) => {
  next(vm => {
    // 执行操作
  })
})

from docute.

egoist avatar egoist commented on May 31, 2024

A simplest solution:

function evalPlugin(ctx) {
  ctx.event.subscribe('content:updated', () => {
    document.querySelectorAll('.content script').forEach(function (el) {
      eval(el.innerHTML) // or new Function
    })
  })
}

from docute.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.