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

XML Formatting Fails for Elements with Dots in Names #888

Closed
commonsguy opened this issue Feb 12, 2016 · 7 comments
Closed

XML Formatting Fails for Elements with Dots in Names #888

commonsguy opened this issue Feb 12, 2016 · 7 comments

Comments

@commonsguy
Copy link

If you have an XML element with dots in the element name, at least for the root element, that element does not get syntax highlighting applied.

<android.support.v7.widget.CardView
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:cardview="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_margin="4dp"
  cardview:cardCornerRadius="4dp"/>

Attached, please find a ZIP file containing two PrismJS samples. The not-working/ one uses an element name of android.support.v7.widget.CardView, and that element does not get syntax-highlighted (though child elements do). The working/ one removes the dots (for a fictitious androidsupportv7widgetCardView element), and that element does get syntax-highlighted. The results are reproducible on Firefox 44, Chromium 48, and the Android 6.0 WebView, at minimum.
prismjs-bug.zip

Let me know if you need additional information -- thanks!

@LeaVerou
Copy link
Member

Should we change the regexp in markup to include periods? Is there anything that could break if we do?

@zeitgeist87
Copy link
Collaborator

The XML specification explicitly allows the . character for tag names:
https://www.w3.org/TR/REC-xml/#NT-Name

But HTML only allows alphanumeric ASCII characters as tag names:
https://www.w3.org/TR/html5/syntax.html#syntax-tag-name

Since Prism is not a parser it should be more permissive and allow the . character, but I don't know if that would cause anything to break...

@Golmote
Copy link
Contributor

Golmote commented Feb 17, 2016

Well we do have tests now, don't we?

@zeitgeist87
Copy link
Collaborator

Well we do have tests now, don't we?

Allowing the . character will break the following Textile-language test:

!<foo.png! !>bar.jpg!

This is recognized as a HTML-tag: <foo.png! !>. Why does Textile extend Markup anyway?

@Golmote
Copy link
Contributor

Golmote commented Feb 20, 2016

Why does Textile extend Markup anyway?

Because it allows HTML:

You can certainly use HTML tags inside your Textile documents.
I am <b>very</b> serious.

http://redcloth.org/hobix.com/textile/#writing-in-textile

@Golmote
Copy link
Contributor

Golmote commented Feb 20, 2016

This is recognized as a HTML-tag: <foo.png! !>

Should we allow the exclamation point though?

@zeitgeist87
Copy link
Collaborator

This is recognized as a HTML-tag: <foo.png! !>
Should we allow the exclamation point though?

If I disallow the exclamation point, then the following line fails:

|_. foo |<_. bar |>_. baz |

because <_. bar |> is recognized as the tag _., with the two boolean attributes bar and |.

Since HTML only allows alpha-numeric tags ànyway we could do this:

Prism.languages.textile.tag.pattern = /<\/?(?!\d)[a-z0-9]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i;

@Golmote Golmote closed this as completed in 31ea66b Jul 3, 2016
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

No branches or pull requests

4 participants