-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: reusable content parser (#838)
* refactor: reusable content parser * chore: prettier * fix: export type * update regex Co-authored-by: Kelly Joseph Price <[email protected]> --------- Co-authored-by: Kelly Joseph Price <[email protected]>
- Loading branch information
1 parent
e6c82db
commit c9a1c1b
Showing
8 changed files
with
105 additions
and
80 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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const { insertBlockTokenizerBefore } = require('./utils'); | ||
|
||
export const type = 'reusable-content'; | ||
|
||
function tokenizeReusableContent(eat, value, silent) { | ||
const { tags, disabled, wrap = true } = this.data('reusableContent'); | ||
if (disabled) return false; | ||
|
||
// Modifies the regular expression to match from | ||
// the start of the line | ||
const match = /^<(?<tag>[A-Z]\S+)\s*\/>\s*\n/.exec(value); | ||
|
||
if (!match || !match.groups.tag) return false; | ||
const { tag } = match.groups; | ||
|
||
/* istanbul ignore if */ | ||
if (silent) return true; | ||
|
||
const node = wrap | ||
? { | ||
type: 'reusable-content', | ||
tag, | ||
children: tag in tags ? tags[tag] : [], | ||
} | ||
: tags[tag]; | ||
|
||
return eat(match[0])(node); | ||
} | ||
|
||
function parser() { | ||
insertBlockTokenizerBefore.call(this, { | ||
name: 'reusableContent', | ||
before: 'html', | ||
tokenizer: tokenizeReusableContent.bind(this), | ||
}); | ||
} | ||
|
||
export default parser; |
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,6 +1,5 @@ | ||
import reusableContent from './reusable-content'; | ||
import singleCodeTabs from './single-code-tabs'; | ||
import tableCellInlineCode from './table-cell-inline-code'; | ||
|
||
export const remarkTransformers = [singleCodeTabs, reusableContent]; | ||
export const remarkTransformers = [singleCodeTabs]; | ||
export const rehypeTransformers = [tableCellInlineCode]; |
This file was deleted.
Oops, something went wrong.