Skip to content

Commit

Permalink
fix(HTMLParser): class attribute does not support multiple values
Browse files Browse the repository at this point in the history
  • Loading branch information
luolonghao committed Jul 10, 2024
1 parent 87379c9 commit 3cce249
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/config/element-rules.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const blockAttributeRules: any = {
id: /^[\w-]+$/,
class: /^[\w-]+$/,
class: /^[\w- ]+$/,
style: {
'text-align': ['left', 'center', 'right', 'justify', 'start', 'end'],
'margin-left': /^-?\d+px$/i,
Expand Down Expand Up @@ -99,7 +99,7 @@ export function getElementRules(): any {
},
},
span: {
class: /^[\w-]+$/,
class: /^[\w- ]+$/,
style: {
color: /^[^"]+$/,
'background-color': /^[^"]+$/,
Expand All @@ -117,7 +117,7 @@ export function getElementRules(): any {
sup: {},
code: {},
a: {
class: /^[\w-]+$/,
class: /^[\w- ]+$/,
name: /^[\w-]+$/,
href: /^[^"]+$/,
target: /^[\w-]+$/,
Expand Down
7 changes: 7 additions & 0 deletions tests/parsers/html-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ describe('parsers / html-parser', () => {
expect(htmlParser.getHTML()).to.equal(output);
});

it('getHTML method: should keep class="a b"', () => {
const input = '<h1 class="one">foo</h1><p class="a b"><span class="a b">bar</span></p>';
const output = '<h1 class="one">foo</h1><p class="a b"><span class="a b">bar</span></p>';
const htmlParser = new HTMLParser(input);
expect(htmlParser.getHTML()).to.equal(output);
});

it('getHTML method: should keep href', () => {
const input = '<a href="http://url/">foo</a>';
const output = input;
Expand Down

0 comments on commit 3cce249

Please sign in to comment.