-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add support for copying assets and replace img src with the …
…proper path in @webdoc/default-template (#170) * Feature: Add support for copying assets and replace img src with the proper path in @webdoc/default-template * Fix lint
- Loading branch information
1 parent
437acf3
commit f6e78da
Showing
8 changed files
with
53 additions
and
9 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
15 changes: 15 additions & 0 deletions
15
packages/webdoc-default-template/helper/renderer-plugins/preprocess.js
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,15 @@ | ||
const path = require("path"); | ||
|
||
// Regex for matching <img> element with a capturing group for src attribute | ||
const IMG_REGEX = /(<img [^<]*src=")([-\]_.~!*'();:@&=+$,/?%#[A-z0-9]*)("[^<]*>)/g; | ||
|
||
exports.preprocessMarkupPlugin = ({ | ||
assetsDir, | ||
}) => function preprocessMarkup( | ||
markup /*: string */, | ||
) /*: string */ { | ||
return markup.replace(IMG_REGEX, | ||
function(_, prefix /*: string */, src /*: string */, suffix /*: string */) { | ||
return `${prefix}/${path.join(assetsDir, String(src).trim())}${suffix}`; | ||
}); | ||
}; |
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
5 changes: 5 additions & 0 deletions
5
packages/webdoc-default-template/tmpl/components/content/text.tmpl
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,5 @@ | ||
<?js | ||
if (typeof obj !== 'string') return; | ||
const text = this.plugins.preprocess(obj); | ||
?> | ||
<?js= text ?> |
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
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