-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for
:link
directive to automatically add npm icon via…
… `style=npm` & properly embed the icon
- Loading branch information
1 parent
d565bbd
commit 50f48f6
Showing
4 changed files
with
71 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,6 @@ import type { UserOptions } from './types.js' | |
*/ | ||
|
||
const remarkDirectiveSugar: Plugin<[UserOptions?], Root> = (options) => { | ||
// get config | ||
const config = getConfig(options) | ||
const { classPrefix, image, link, video, badge } = config | ||
|
||
|
@@ -126,13 +125,10 @@ const remarkDirectiveSugar: Plugin<[UserOptions?], Root> = (options) => { | |
data.hName = 'a' | ||
const defaultAttributes = { target: '_blank' } | ||
data.hProperties = { ...defaultAttributes, ...attributes } | ||
} else if (imageRegex.test(node.name)) { | ||
} else { | ||
/* image-* */ | ||
const match = node.name.match(imageRegex) | ||
if (match && validTagsForImg.has(match[1])) { | ||
/* const data = node.data || (node.data = {}) | ||
const attributes = node.attributes || {} */ | ||
|
||
data.hName = match[1] | ||
data.hProperties = attributes | ||
} else { | ||
|
@@ -329,25 +325,42 @@ const remarkDirectiveSugar: Plugin<[UserOptions?], Root> = (options) => { | |
value: resolvedText, | ||
}, | ||
] | ||
} else if (resolvedStyle === 'github') { | ||
} else if ( | ||
resolvedStyle === 'github' || | ||
resolvedStyle === 'npm' | ||
) { | ||
data.hName = 'span' | ||
data.hProperties = { | ||
style: 'white-space: nowrap', | ||
} | ||
data.hChildren = [ | ||
{ | ||
type: 'element', | ||
tagName: 'span', | ||
tagName: 'svg', | ||
properties: { | ||
class: 'i-carbon-logo-github', | ||
xmlns: 'http://www.w3.org/2000/svg', | ||
width: '1.2em', | ||
height: '1.2em', | ||
viewBox: '0 0 32 32', | ||
ariaHidden: 'true', | ||
}, | ||
children: [], | ||
children: [ | ||
{ | ||
type: 'element', | ||
tagName: 'path', | ||
properties: { | ||
fill: 'currentColor', | ||
d: iconSvgPath[resolvedStyle], | ||
Check failure on line 353 in src/index.ts
|
||
}, | ||
children: [], | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'element', | ||
tagName: 'a', | ||
properties: { | ||
class: `${classPrefix}-link-github`, | ||
class: `${classPrefix}-link-${resolvedStyle}`, | ||
href: resolvedLink, | ||
}, | ||
children: [{ type: 'text', value: resolvedText }], | ||
|
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