-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
All my changes (don't merge) #1091
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
Changes from all commits
bedd47a
fc5a937
91ea8f2
ae01327
01f00b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,10 +237,16 @@ export class Compiler { | |
!_self._matchNotCompileLink(href) && | ||
!config.ignore | ||
) { | ||
if (href === _self.config.homepage) { | ||
href = 'README' | ||
// skip hrefs like `#/page?id=section`, which are already in the format | ||
// Docsify compiles hrefs to | ||
// TODO move this to router.toURL | ||
// TODO make a note of why we need this | ||
if (!href.trim().startsWith('#/')) { | ||
if (href === _self.config.homepage) { | ||
href = 'README' | ||
} | ||
href = router.toURL(href, null, router.getCurrentPath()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the comment says, this prevents Docsify from erroneously handling links that are already in Docsify's format. This makes it easy to link to known pages if you already know the URL you want to link to. I think this is related to the next comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember why I needed this. I'll report back after some investigation. |
||
} | ||
href = router.toURL(href, null, router.getCurrentPath()) | ||
} else { | ||
attrs += href.indexOf('mailto:') === 0 ? '' : ` target="${linkTarget}"` | ||
} | ||
|
@@ -258,7 +264,7 @@ export class Compiler { | |
attrs += ` title="${title}"` | ||
} | ||
|
||
return `<a href="${href}"${attrs}>${text}</a>` | ||
return `<a docsify-link href="${href}"${attrs}>${text}</a>` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed a way in my own code to detect Docsify links. The reason is that I have a custom This is my markdown: {
// `this` in the following hooks is an instace of Marked Renderer
renderer: {
html(html) {
const matches = html.matchAll(reAnchorWithHref)
const {linkTarget, router} = vm.compiler
// if we find an anchor tag with an href attribute
for (const match of matches) {
// if the link is a Docsify link generated from markdown, skip it, it is already handled
if (match[0].startsWith('<a docsify-link')) continue // <--------------------- HERE
// the result will be one of the three capturing groups from the regex
let href = match[1] || match[2] || match[3]
const originalHref = href
// the first two capturing groups catch single or double quoted values
const hasQuotes = !!(match[1] || match[2])
// based on Docsify's Compiler._initRenderer() logic for the markdown "link" hook {{{
// TODO make some syntax for telling it to ignore the compiling the href
const ignoreLink = false
if (
!Docsify.util.isAbsolutePath(href) &&
!vm.compiler._matchNotCompileLink(href) &&
!ignoreLink &&
// skip hrefs like `#/page?id=section`, which
// are already in the format Docsify compiles
// hrefs to
// TODO move this to router.toURL
!href.trim().startsWith('#/')
) {
if (href === vm.compiler.config.homepage) {
href = 'README'
}
href = router.toURL(href, null, router.getCurrentPath())
}
// }}}
if (!hasQuotes) href = '"' + href + '"'
html = html.replace(originalHref, href)
}
return html
}, I need to think about if this is the best way to do what I wanted, but I don't remember what problem I needed to solve. I'll need to disable this and see how it breaks my links so I can remember. 😄 Some of the logic is duplicated from other code inside Docsify, which isn't ideal. Let me think of how it can be easier... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for, this I think we can have a use case if we reshape this a little. like mentioned here in this issue #1088 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note also this piece of code is where I needed the
Gotcha, so if it had that feature then I could detect the ID prefix, similar to what I did with the |
||
} | ||
origin.paragraph = renderer.paragraph = function (text) { | ||
let result | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,29 @@ import {isPrimitive} from '../util/core' | |
import {scrollActiveSidebar, scroll2Top} from '../event/scroll' | ||
import {prerenderEmbed} from './embed' | ||
|
||
function executeScript() { | ||
function getScript() { | ||
const script = dom | ||
.findAll('.markdown-section>script') | ||
.filter(s => !/template/.test(s.type))[0] | ||
|
||
if (!script) { | ||
return false | ||
return null | ||
} | ||
|
||
const code = script.innerText.trim() | ||
|
||
if (!code) { | ||
return false | ||
return null | ||
} | ||
|
||
return code | ||
} | ||
|
||
function executeScript() { | ||
const code = getScript() | ||
|
||
if (!code) return | ||
|
||
setTimeout(_ => { | ||
window.__EXECUTE_RESULT__ = new Function(code)() | ||
}, 0) | ||
|
@@ -52,13 +63,14 @@ function renderMain(html) { | |
if ( | ||
this.config.executeScript !== false && | ||
typeof window.Vue !== 'undefined' && | ||
!executeScript() | ||
// !executeScript() | ||
!getScript() | ||
) { | ||
setTimeout(_ => { | ||
// setTimeout(_ => { | ||
const vueVM = window.__EXECUTE_RESULT__ | ||
vueVM && vueVM.$destroy && vueVM.$destroy() | ||
window.__EXECUTE_RESULT__ = new window.Vue().$mount('#main') | ||
}, 0) | ||
// }, 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes with getScript/executeScript prevents script tags from executing twice. The Maybe it was a hack to defer script execution to later so that things in the DOM are ready? If that's the case, users can for example use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it will effect the custom scrip option which are defined in the markdown right ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can you expand on this? |
||
} else { | ||
this.config.executeScript && executeScript() | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.