Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add XML Parsing with DocXmlElement #331

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
197a2de
chore: initial working commit
suneettipirneni Aug 1, 2022
f31d7dc
chore: add support for plaintext and fix recursion bug
suneettipirneni Aug 2, 2022
96d65b6
refactor: decapitalize XML
suneettipirneni Aug 2, 2022
b9f25c1
fix: make emitter emit xml elements properly
suneettipirneni Aug 3, 2022
4c37235
test: add tests
suneettipirneni Aug 3, 2022
8bca007
chore: update changelog
suneettipirneni Aug 3, 2022
d825766
fix: propertly emit spacing after tag name, and attributes for self c…
suneettipirneni Aug 4, 2022
748d764
Merge branch 'main' of https://github.com/microsoft/tsdoc into feat/d…
suneettipirneni Aug 4, 2022
23c2813
test: fix tests
suneettipirneni Aug 4, 2022
dcc0536
fix: properly parse XML inner text nodes
suneettipirneni Aug 5, 2022
af36851
chore: improve error range for mismatched tag names
suneettipirneni Aug 5, 2022
7e437f3
refactor: extract inner text parsing and add syntax highlighting
suneettipirneni Aug 8, 2022
2f6849e
chore: fix CI filename issue
suneettipirneni Aug 8, 2022
8402e1c
Make requested changelog changes
suneettipirneni Aug 10, 2022
9d9b5c6
fix: make sure xml elements don't have duplicate attribute names
suneettipirneni Aug 10, 2022
54a41f6
improve readability of unterminated XML element errors
suneettipirneni Aug 10, 2022
38a77b1
adjust description for xml tag name mismatches
suneettipirneni Aug 10, 2022
7065353
Merge branch 'feat/docxmlnodes' of https://github.com/suneettipirneni…
suneettipirneni Aug 10, 2022
3d8bc41
parse softbreaks from newlines in xml inner text
suneettipirneni Aug 10, 2022
879e481
fix tests
suneettipirneni Aug 10, 2022
1c4ba09
add DocXmlElement#tryGetXmlAttribute
suneettipirneni Aug 11, 2022
72a3545
fix param linting
suneettipirneni Aug 11, 2022
7c19834
preserve loose xml elements when errors occur
suneettipirneni Aug 26, 2022
8cde107
fix error typo
suneettipirneni Aug 26, 2022
30e4f43
don't return plaintext
suneettipirneni Aug 26, 2022
0f02b6a
fix tag mismatch typos
suneettipirneni Aug 26, 2022
fa9ed9c
regenerate snapshots
suneettipirneni Aug 28, 2022
03116d8
Update change files
octogonz Sep 2, 2022
1d491a1
Fix a mistake in RegExp
octogonz Sep 14, 2022
e6a00a5
Rename "selfClosingTag" -> "isEmptyElement" since DocXmlElement repre…
octogonz Sep 14, 2022
274a46f
Improve tryGetXmlAttribute() validation
octogonz Sep 14, 2022
db9574c
Update change files
octogonz Sep 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/tsdoc-config",
"comment": "(BREAKING SCHEMA CHANGE) Rename tsdoc.json fields: \"supportedHtmlElements\" renamed to \"supportedXmlElements\"; \"reportUnsupportedHtmlElements\" renamed to \"reportUnsupportedXmlElements\"",
"type": "minor"
}
],
"packageName": "@microsoft/tsdoc-config",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/tsdoc-config",
"comment": "(BREAKING API CHANGE) Rename several APIs to use the name \"Xml\" instead of \"Html\". For example, TSDocConfigFile.addSupportedHtmlElement() was renamed to TSDocConfigFile.addSupportedXmlElement().",
"type": "minor"
}
],
"packageName": "@microsoft/tsdoc-config",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/tsdoc",
"comment": "(BREAKING API CHANGE) Replace AST nodes `DocHtmlStartTag` and `DocHtmlEndTag` with a new node `DocXmlElement` that represents a hierarchical DOM tree",
"type": "minor"
}
],
"packageName": "@microsoft/tsdoc",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/tsdoc",
"comment": "(BREAKING SYNTAX CHANGE) Improve the parser to report syntax errors if opening/closing XML tags are not correctly matched",
"type": "minor"
}
],
"packageName": "@microsoft/tsdoc",
"email": "[email protected]"
}
19 changes: 10 additions & 9 deletions playground/src/SyntaxStyler/DocNodeSyntaxStyler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ export class DocNodeSyntaxStyler {
case 'DocMemberSymbol_RightBracket':
case 'FencedCode_ClosingFence':
case 'FencedCode_OpeningFence':
case 'HtmlAttribute_Equals':
case 'HtmlEndTag_ClosingDelimiter':
case 'HtmlEndTag_OpeningDelimiter':
case 'HtmlStartTag_ClosingDelimiter':
case 'HtmlStartTag_OpeningDelimiter':
case 'XmlAttribute_Equals':
case 'XmlEndTag_ClosingDelimiter':
case 'XmlEndTag_OpeningDelimiter':
case 'XmlStartTag_ClosingDelimiter':
case 'XmlStartTag_OpeningDelimiter':
case 'InlineTag_ClosingDelimiter':
case 'InlineTag_OpeningDelimiter':
case 'LinkTag_Pipe':
Expand Down Expand Up @@ -155,24 +155,25 @@ export class DocNodeSyntaxStyler {
break;
}

case 'HtmlEndTag_Name':
case 'HtmlStartTag_Name': {
case 'XmlElement_Name':
case 'XmlEndTag_Name':
case 'XmlStartTag_Name': {
DocNodeSyntaxStyler._addTokenStyles(styles, docNode.content, {
theme,
styleTokens: [...styleTokens, 'element', 'name']
});
break;
}

case 'HtmlAttribute_Name': {
case 'XmlAttribute_Name': {
DocNodeSyntaxStyler._addTokenStyles(styles, docNode.content, {
theme,
styleTokens: [...styleTokens, 'element', 'attribute', 'name']
});
break;
}

case 'HtmlAttribute_Value': {
case 'XmlAttribute_Value': {
DocNodeSyntaxStyler._addTokenStyles(styles, docNode.content, {
theme,
styleTokens: [...styleTokens, 'element', 'attribute', 'value']
Expand Down
72 changes: 36 additions & 36 deletions tsdoc-config/src/TSDocConfigFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ interface IConfigJson {
noStandardTags?: boolean;
tagDefinitions?: ITagConfigJson[];
supportForTags?: { [tagName: string]: boolean };
supportedHtmlElements?: string[];
reportUnsupportedHtmlElements?: boolean;
supportedXmlElements?: string[];
reportUnsupportedXmlElements?: boolean;
}

/**
Expand Down Expand Up @@ -71,8 +71,8 @@ export class TSDocConfigFile {
private readonly _tagDefinitions: TSDocTagDefinition[];
private readonly _tagDefinitionNames: Set<string>;
private readonly _supportForTags: Map<string, boolean>;
private _supportedHtmlElements: Set<string> | undefined;
private _reportUnsupportedHtmlElements: boolean | undefined;
private _supportedXmlElements: Set<string> | undefined;
private _reportUnsupportedXmlElements: boolean | undefined;

private constructor() {
this.log = new ParserMessageLog();
Expand Down Expand Up @@ -171,16 +171,16 @@ export class TSDocConfigFile {
return this._supportForTags;
}

public get supportedHtmlElements(): ReadonlyArray<string> | undefined {
return this._supportedHtmlElements && Array.from(this._supportedHtmlElements);
public get supportedXmlElements(): ReadonlyArray<string> | undefined {
return this._supportedXmlElements && Array.from(this._supportedXmlElements);
}

public get reportUnsupportedHtmlElements(): boolean | undefined {
return this._reportUnsupportedHtmlElements;
public get reportUnsupportedXmlElements(): boolean | undefined {
return this._reportUnsupportedXmlElements;
}

public set reportUnsupportedHtmlElements(value: boolean | undefined) {
this._reportUnsupportedHtmlElements = value;
public set reportUnsupportedXmlElements(value: boolean | undefined) {
this._reportUnsupportedXmlElements = value;
}

/**
Expand Down Expand Up @@ -234,20 +234,20 @@ export class TSDocConfigFile {
}

/**
* Adds a new item to the `supportedHtmlElements` array.
* Adds a new item to the `supportedXmlElements` array.
*/
public addSupportedHtmlElement(htmlElement: string): void {
if (!this._supportedHtmlElements) {
this._supportedHtmlElements = new Set();
public addSupportedXmlElement(xmlElement: string): void {
if (!this._supportedXmlElements) {
this._supportedXmlElements = new Set();
}
this._supportedHtmlElements.add(htmlElement);
this._supportedXmlElements.add(xmlElement);
}

/**
* Removes the explicit list of allowed html elements.
* Removes the explicit list of allowed xml elements.
*/
public clearSupportedHtmlElements(): void {
this._supportedHtmlElements = undefined;
public clearSupportedXmlElements(): void {
this._supportedXmlElements = undefined;
}

/**
Expand Down Expand Up @@ -367,14 +367,14 @@ export class TSDocConfigFile {
});
}

if (configJson.supportedHtmlElements) {
this._supportedHtmlElements = new Set();
for (const htmlElement of configJson.supportedHtmlElements) {
this.addSupportedHtmlElement(htmlElement);
if (configJson.supportedXmlElements) {
this._supportedXmlElements = new Set();
for (const xmlElement of configJson.supportedXmlElements) {
this.addSupportedXmlElement(xmlElement);
}
}

this._reportUnsupportedHtmlElements = configJson.reportUnsupportedHtmlElements;
this._reportUnsupportedXmlElements = configJson.reportUnsupportedXmlElements;

if (configJson.supportForTags) {
for (const tagName of Object.keys(configJson.supportForTags)) {
Expand Down Expand Up @@ -595,11 +595,11 @@ export class TSDocConfigFile {
configFile.setSupportForTag(tagDefinition.tagName, true);
}

for (const htmlElement of configuration.supportedHtmlElements) {
configFile.addSupportedHtmlElement(htmlElement);
for (const xmlElement of configuration.supportedXmlElements) {
configFile.addSupportedXmlElement(xmlElement);
}

configFile.reportUnsupportedHtmlElements = configuration.validation.reportUnsupportedHtmlElements;
configFile.reportUnsupportedXmlElements = configuration.validation.reportUnsupportedXmlElements;

return configFile;
}
Expand Down Expand Up @@ -639,12 +639,12 @@ export class TSDocConfigFile {
});
}

if (this.supportedHtmlElements) {
configJson.supportedHtmlElements = [...this.supportedHtmlElements];
if (this.supportedXmlElements) {
configJson.supportedXmlElements = [...this.supportedXmlElements];
}

if (this._reportUnsupportedHtmlElements !== undefined) {
configJson.reportUnsupportedHtmlElements = this._reportUnsupportedHtmlElements;
if (this._reportUnsupportedXmlElements !== undefined) {
configJson.reportUnsupportedXmlElements = this._reportUnsupportedXmlElements;
}

return configJson;
Expand Down Expand Up @@ -769,14 +769,14 @@ export class TSDocConfigFile {
}
});

if (this.supportedHtmlElements) {
configuration.setSupportedHtmlElements([...this.supportedHtmlElements]);
if (this.supportedXmlElements) {
configuration.setSupportedXmlElements([...this.supportedXmlElements]);
}

if (this._reportUnsupportedHtmlElements === false) {
configuration.validation.reportUnsupportedHtmlElements = false;
} else if (this._reportUnsupportedHtmlElements === true) {
configuration.validation.reportUnsupportedHtmlElements = true;
if (this._reportUnsupportedXmlElements === false) {
configuration.validation.reportUnsupportedXmlElements = false;
} else if (this._reportUnsupportedXmlElements === true) {
configuration.validation.reportUnsupportedXmlElements = true;
}
}

Expand Down