Skip to content

feat: add an option to customize tag content type #12

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

Merged
merged 1 commit into from
Apr 21, 2020

Conversation

ikatyang
Copy link
Member

Fixes #11

The tag content type resolution happens in the lexing phase so there is no info for element stack, i.e., something like getTagContentType(tagName, elementStack) is not possible under this architecture, which means there is no way to identify if an element is a root element, so we probably need to do two-pass parsing for the Vue SFC, one for the root elements and one for <template>s.

cc @sosukesuzuki @fisker @thorn0

@fisker
Copy link
Member

fisker commented Apr 19, 2020

To parse Vue SFC, we need paser everything as RAW_TEXT first, then parse template?

@ikatyang
Copy link
Member Author

To parse Vue SFC, we need paser everything as RAW_TEXT first, then parse template?

Yes.

@thorn0
Copy link
Member

thorn0 commented Apr 19, 2020

I'm not a Vue user, but there are claims that it supports // comments, so tags inside those should be not parsed as tags. Can somebody confirm or deny this?

@fisker
Copy link
Member

fisker commented Apr 19, 2020

I guess it's possible that <template> contains script/style, if so on template parsing, we just use getTagContentType: undefined, it will work like before, right?

@fisker
Copy link
Member

fisker commented Apr 19, 2020

@thorn0 I'm not sure about //, but I can confirm it supports /* */, I saw one last week , from my work. To make it work with prettier, I changed it to html style comment.

Here

@ikatyang
Copy link
Member Author

I guess it's possible that <template> contains script/style, if so on template parsing, we just use getTagContentType: undefined, it will work like before, right?

Right, getTagContentType defaults to the content type defined in the HTML spec.

I'm not a Vue user, but there are claims that it supports // comments, so tags inside those should be not parsed as tags. Can somebody confirm or deny this?

const {parse} = require("@vue/compiler-sfc"); // 3.0.0-beta.2
const parsed = parse(`
<template><div></div></template>
<script>export default { }</script>
// <abc>
<style></style>
`);
console.log(parsed.errors) // ["SyntaxError: Element is missing end tag (4:4)"]

I'm not sure about //, but I can confirm it supports /* */, I saw one last week , from my work. To make it work with prettier, I changed it to html style comment.

Here

See https://vue-loader.vuejs.org/spec.html#comments.

@ikatyang
Copy link
Member Author

I'll merge this PR tomorrow if there is no objection/question.

@fisker
Copy link
Member

fisker commented Apr 20, 2020

I checked the "Vue SFC Spec" about comments before, but people actually use js style comments, and at least it works in @vue/cli AFAIK.

@ikatyang
Copy link
Member Author

Relying on the implementation detail does not look like a good idea, I think we should follow the spec and push people to use the correct comment style just like what you did.

@fisker
Copy link
Member

fisker commented Apr 21, 2020

Looking forward to see improve vue parse with this.

@ikatyang ikatyang merged commit b327e1a into master Apr 21, 2020
@ikatyang ikatyang deleted the feat/get-tag-content-type branch April 21, 2020 11:56
@ikatyang
Copy link
Member Author

👉 https://github.com/ikatyang/angular-html-parser/releases/tag/v1.5.0

@sosukesuzuki
Copy link
Member

@ikatyang Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to parse a content of unknown tags in root as string
4 participants