ctrl+k
Enter a search term above to see results...
Methods for parsing HTML and extracting semantic component structure.
Parses HTML and extracts semantic component structure. Returns component name, attributes, and inner content.
reader.getComponentPartsFromHTML(html, options)| Name | Type | Default | Description |
|---|---|---|---|
| html | string | HTML string to parse | |
| options | Object | Parse options | |
| options.dialect | string | this.dialect | HTML dialect to use |
| Property | Type | Description |
|---|---|---|
| componentName | string | Component tag name |
| attributes | Object | Attribute key-value pairs |
| attributeString | string | Formatted attribute string |
| html | string | Inner HTML content |
import { SpecReader } from '@semantic-ui/specs';import buttonSpec from './button.spec.js';
const reader = new SpecReader(buttonSpec);const parts = reader.getComponentPartsFromHTML( '<ui-button primary large>Save</ui-button>');
console.log(parts);// {// componentName: 'ui-button',// attributes: { primary: true, large: true },// attributeString: 'primary large',// html: 'Save'// }Parse with verbose dialect:
const parts = reader.getComponentPartsFromHTML( '<ui-button emphasis="primary" size="large">Save</ui-button>', { dialect: 'verbose' });
console.log(parts);// {// componentName: 'ui-button',// attributes: { emphasis: 'primary', size: 'large' },// attributeString: 'emphasis="primary" size="large"',// html: 'Save'// }Converts semantic modifier string into attribute object. Parses space-separated modifiers and maps them to their semantic attributes.
reader.getAttributesFromModifiers(modifiers)| Name | Type | Description |
|---|---|---|
| modifiers | string | Space-separated semantic modifiers |
Object with attribute keys and values.
import { SpecReader } from '@semantic-ui/specs';import buttonSpec from './button.spec.js';
const reader = new SpecReader(buttonSpec);const attributes = reader.getAttributesFromModifiers('primary large');
console.log(attributes);// {// emphasis: 'primary',// size: 'large'// }Boolean attributes:
const attributes = reader.getAttributesFromModifiers('disabled loading');
console.log(attributes);// {// disabled: true,// loading: true// }