-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add serve node module to docs * chore: fix generate build command * chore: fix ts build * chore: fix ts build issues and sync all deps * chore: fix i18n build error * fix(docs): markdownit build error * fix: types build and update ts to ^5.0 * raw new markdown * fix(docs): memory leaks in ssr * fix(build): typo * fix(docs): show old props with vue-component-meta * raw markdown plugins * fix(docs): external links * fix(docs): update node to 18 * docs(chore): remove markdown-it * fix(deps): remove hardcoded deps * chore(deps): update ts to 5 * chore(deps): update eslint to ^7
- Loading branch information
Showing
67 changed files
with
4,300 additions
and
5,587 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v16.16.0 | ||
v18.14.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
packages/docs/modules/markdown/runtime/plugins/external-links.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { it, describe, expect } from 'vitest'; | ||
import { marked } from 'marked'; | ||
import { fixTargetLinks } from './external-links'; | ||
|
||
describe('externalLinkMarkedPlugin', () => { | ||
it('targetBlankPlugin: adds target="_blank" to links', () => { | ||
const markdown = `[vue-press](https://vuepress.vuejs.org/)[[target=_blank]]`; | ||
const html = fixTargetLinks(marked(markdown)); | ||
|
||
expect(/target="_blank"/.test(html)).toBeTruthy(); | ||
}); | ||
}) | ||
|
24 changes: 24 additions & 0 deletions
24
packages/docs/modules/markdown/runtime/plugins/external-links.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const addAttrToLink = (str: string, attr: string) => { | ||
const [start, end] = str.split('<a') | ||
return start + '<a ' + attr + end | ||
} | ||
|
||
export const fixTargetLinks = (textToRender: string) => { | ||
const targetRegex = /\[\[(.*?)\]\]/g; // Search for the [[target="_blank"]] in the markdown. | ||
const linkRegexPattern = /<a[^>]*>.*<\/a>\[\[(.*)\]\]/g; // Searching for all <a href=""> tags | ||
|
||
let matchedTarget; | ||
|
||
while ((matchedTarget = linkRegexPattern.exec(textToRender)) !== null) { | ||
let target = matchedTarget[1].trim().replaceAll('"', '"') | ||
if (target === 'target=_blank') { | ||
target = 'target="_blank"'; | ||
} | ||
const [link] = matchedTarget | ||
|
||
textToRender = addAttrToLink(textToRender | ||
.replace(link, link.replace(targetRegex, '')), target) | ||
} | ||
|
||
return textToRender; | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/docs/modules/markdown/runtime/plugins/localized-links.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Renderer, Parser } from 'marked' | ||
import { Ref } from 'vue' | ||
export const externalLinkStartWith = ['http://', 'https://'] | ||
|
||
export function localizedLinkMarkedPlugin(locale: Ref<string>) { | ||
const renderer = new Renderer(); | ||
const originalRenderer = renderer.link; | ||
|
||
renderer.link = function (href, title, text) { | ||
const isExternalLink = externalLinkStartWith.some((item) => href?.startsWith(item)) | ||
|
||
if (isExternalLink) { | ||
return originalRenderer.call(renderer, href, title, text); | ||
} | ||
|
||
const normalizedHref = href?.startsWith('/') | ||
? href.substring(1) | ||
: href | ||
|
||
const localePrefix = `${locale.value}/` | ||
|
||
if (normalizedHref?.startsWith(localePrefix)) { | ||
return originalRenderer.call(renderer, href, title, text); | ||
} | ||
|
||
return originalRenderer.call(renderer, '/' + localePrefix + href, title, text); | ||
} | ||
|
||
return { renderer }; | ||
} |
23 changes: 0 additions & 23 deletions
23
packages/docs/modules/markdown/runtime/rules/set-class-attribute-to-external-links.ts
This file was deleted.
Oops, something went wrong.
53 changes: 0 additions & 53 deletions
53
packages/docs/modules/markdown/runtime/rules/set-origin-location-to-relative-links.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { InjectionKey } from "vue" | ||
import { marked } from 'marked'; | ||
import { fixTargetLinks } from "./plugins/external-links"; | ||
import { localizedLinkMarkedPlugin } from './plugins/localized-links' | ||
|
||
let localizePlugin: null | ReturnType<typeof localizedLinkMarkedPlugin> = null | ||
|
||
export const useMarkdownProvideKey = 'vuestic:markdown' as unknown as InjectionKey<ReturnType<typeof marked>> | ||
|
||
export const useMarkdown = () => { | ||
const { locale } = useI18n() | ||
|
||
if (!localizePlugin) { | ||
localizePlugin = localizedLinkMarkedPlugin(locale) | ||
marked.use(localizePlugin) | ||
} else { | ||
marked.use(localizePlugin) | ||
} | ||
|
||
const parse = (markdown: string) => { | ||
return fixTargetLinks((marked.parse(markdown)).toString()) | ||
} | ||
|
||
const parseInline = (markdown: string) => { | ||
return fixTargetLinks((marked.parseInline(markdown)).toString()) | ||
} | ||
|
||
return { parse, parseInline } | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.