Comments (8)
这是因为动态添加的 html string 里的 script 不会被执行,解决办法大概是:
- 在解析 markdown 之后把 html string 里 script 的内容抽出来然后单独创建一个 script 元素添加到 body 末尾
- 或者直接 eval/new Function 这个 html string 来执行里面的 script 代码
不过我觉得还是写在单独的 js 文件里比较好,因为动态添加的内容执行 js 之后作用是全局的,因为不会需要重新刷新整个页面,各个页面的 js 可能互相影响,那不如直接写在单独的文件里直接在 index.html 中加载。
from docute.
比方说我要在某段文本后面加入codepen的演示例子,不支持script标签的话就没有办法演示,大概是这个意思。。
from docute.
没考虑到这个
from docute.
:) 嗯嗯,期待~Thanks for your work
from docute.
不过 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.
get
from docute.
额,其实可以用户自己实现这个功能了,现在提供了 vue-router 的 API,比如:
docute.router.afterEach((to, from, next) => {
next(vm => {
// 执行操作
})
})
from docute.
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)
- JS.ORG CLEANUP HOT 1
- Children in children not working HOT 2
- Documentation does not indicate how to install HOT 1
- Multi-level menu
- Fix Repl.it example HOT 1
- Question: How to change the theme of code highlight?
- Deploy to gitlab pages
- Multilanguage with LTR and RTL languges HOT 2
- Ability for a standalone file:// is broken HOT 3
- Select has inverted colors in dark theme
- Theme search function
- api.onUpdate causes rendering to fail
- Support explicit markdown URLs like docsify
- double horizontal scroll bar in code snippets
- use with `router-link`
- [Feature Request] any chance we get React in markdown support?
- Bug: The vue template doesn't work on the sidebar!
- Bug: "router.base" not work! HOT 1
- Unable to jump between level 1 menus
- docute.org seems to be dead HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docute.