Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nxdev): add markdown display features (#5601)
- Loading branch information
Showing
9 changed files
with
558 additions
and
12 deletions.
There are no files selected for viewing
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 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
21 changes: 21 additions & 0 deletions
21
nx-dev/feature-doc-viewer/src/lib/renderers/render-iframe.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,21 @@ | ||
export function renderIframes(): (tree: any) => void { | ||
return (tree): void => { | ||
const iframeList = tree.children.filter( | ||
(child) => child.type === 'raw' && child.value.includes('<iframe') | ||
); | ||
iframeList.forEach((item) => { | ||
item.type = 'element'; | ||
item.tagName = 'iframe'; | ||
item.children = []; | ||
item.properties = {}; | ||
let match; | ||
const regex = new RegExp( | ||
'[\\s\\r\\t\\n]*([a-z0-9\\-_]+)[\\s\\r\\t\\n]*=[\\s\\r\\t\\n]*([\'"])((?:\\\\\\2|(?!\\2).)*)\\2', | ||
'ig' | ||
); | ||
while ((match = regex.exec(item.value))) { | ||
item.properties[match[1]] = match[3]; | ||
} | ||
}); | ||
}; | ||
} |
10 changes: 10 additions & 0 deletions
10
nx-dev/feature-doc-viewer/src/lib/renderers/transform-image-path.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,10 @@ | ||
import { uriTransformer } from 'react-markdown'; | ||
|
||
export function transformImagePath(version: string): (src: string) => string { | ||
return (src) => { | ||
if (/\.(gif|jpe?g|tiff?|png|webp|bmp)$/i.test(src)) { | ||
src = `/${version}`.concat(src); // TODO: copy imgs into public folder, by version id | ||
} | ||
return uriTransformer(src); | ||
}; | ||
} |
18 changes: 18 additions & 0 deletions
18
nx-dev/feature-doc-viewer/src/lib/renderers/transform-link-path.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,18 @@ | ||
import { uriTransformer } from 'react-markdown'; | ||
|
||
export function transformLinkPath(options: { | ||
flavor: string; | ||
version: string; | ||
}): (href) => string { | ||
return (href) => | ||
uriTransformer( | ||
href | ||
? href | ||
.replace( | ||
'%7B%7Bframework%7D%7D', | ||
`${options.version}/${options.flavor}` | ||
) | ||
.replace('%7B%7Bversion%7D%7D', options.version) | ||
: href | ||
); | ||
} |
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
Oops, something went wrong.