-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provide cleanupTitle to trim text contents of title elements
Fixes #2052
- Loading branch information
1 parent
b1e50bd
commit 6f74713
Showing
5 changed files
with
47 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: cleanupTitle | ||
svgo: | ||
pluginId: cleanupTitle | ||
--- | ||
|
||
Trims the text contents of [`<title>`](https://developer.mozilla.org/docs/Web/SVG/Element/title) elements. | ||
|
||
::: |
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,24 @@ | ||
export const name = 'cleanupTitle'; | ||
export const description = 'trims the text contents of <title> elements'; | ||
|
||
/** | ||
* Trims the text contents of <title> elements. | ||
* | ||
* @type {import('./plugins-types.js').Plugin<'cleanupTitle'>} | ||
*/ | ||
export const fn = () => { | ||
return { | ||
element: { | ||
enter: (node) => { | ||
if (node.name === 'title') { | ||
node.children = node.children.map((child) => { | ||
if (child.type === 'text') { | ||
child.value = child.value.trim(); | ||
} | ||
return child; | ||
}); | ||
} | ||
}, | ||
}, | ||
}; | ||
}; |
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,11 @@ | ||
<svg xmlns="http://www.w3.org/2000/svg"> | ||
<title> A title isn't indented, but is escaped and terminally trimmed. </title> | ||
<g/> | ||
</svg> | ||
|
||
@@@ | ||
|
||
<svg xmlns="http://www.w3.org/2000/svg"> | ||
<title>A title isn't indented, but is escaped and terminally trimmed.</title> | ||
<g/> | ||
</svg> |