File tree Expand file tree Collapse file tree
packages/landing/src/pages Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,14 +14,33 @@ const __dirname = dirname(__filename);
1414const readmePath = join (__dirname , ' ../../../../README.md' );
1515const readmeContent = readFileSync (readmePath , ' utf-8' );
1616
17+ const GITHUB_BLOB =
18+ ' https://github.com/junhoyeo/contrabass/blob/main/' ;
19+ const GITHUB_TREE =
20+ ' https://github.com/junhoyeo/contrabass/tree/main/' ;
21+
22+ function isRelative(href : string ): boolean {
23+ return !! href && ! href .startsWith (' http' ) && ! href .startsWith (' #' ) && ! href .startsWith (' mailto:' );
24+ }
25+
1726const parser = new Marked (
1827 markedHighlight ({
1928 langPrefix: ' hljs language-' ,
2029 highlight(code , lang ) {
2130 const language = lang && hljs .getLanguage (lang ) ? lang : ' plaintext' ;
2231 return hljs .highlight (code , { language }).value ;
2332 },
24- })
33+ }),
34+ {
35+ walkTokens(token ) {
36+ if (token .type === ' link' && isRelative (token .href )) {
37+ token .href = (token .href .endsWith (' /' ) ? GITHUB_TREE : GITHUB_BLOB ) + token .href ;
38+ }
39+ if (token .type === ' image' && isRelative (token .href )) {
40+ token .href = GITHUB_BLOB + token .href ;
41+ }
42+ },
43+ },
2544);
2645
2746const htmlContent = parser .parse (readmeContent );
You can’t perform that action at this time.
0 commit comments