Skip to content

Hotfix Expression language example lower than #17587

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

Closed

Conversation

alamirault
Copy link
Contributor

On this page https://symfony.com/doc/current/components/expression_language.html#how-can-the-expression-engine-help-me

product.stock < 15 is not correctly displayed. I see product.stock 15

Examining html code is <code>...product.stock 15</code>.

Locally generated code is <pre class="hljs text">...product.stock < 15...</pre>

I found some places where &lt is used, I think it could fix rendering.
There is no other .rst file where < is used

@carsonbot carsonbot added this to the 5.4 milestone Dec 18, 2022
@@ -41,7 +41,7 @@ way without using PHP and without introducing security problems:
article.commentCount > 100 and article.category not in ["misc"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we should fix this, too, right?

I am wondering if we should keep the > and not use &lt; and fix the docs builder instead, because we are in a .. code-block:: text.

WDYT @weaverryan ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woh. This is kind of "spooky". On the target page - https://symfony.com/doc/current/components/expression_language.html#how-can-the-expression-engine-help-me - the > renders fine here. It even renders as &gt; in the page source. It is only the < below that is missing - completely unrendered on the page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikophil as you worked a lot on the docs-builder, maybe do you have an idea?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi! sorry for the late answer here 😊

I really don't know, it's been literally years that I have not worked on this 🤷

that's really strange this is not rendered the same way locally and on symfony.com: the variable is used the same way in both templates: {{ code|raw }} (see here and here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be a highlight.js issue ? <pre class="hljs text">

Copy link
Contributor

@nikophil nikophil Dec 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I found where the problem is coming from in the docs builder.

For symfony.com, files are rendered as fjson files: we loop on each html file, take the content of the <body> tag thanks to symfony/dom-crawler and put it in a fjson file.

The symbol < disappears after the crawler step (it might assume it is an error in the html syntax? don't really know 🤷)

Here, the content of file_get_contents()has the symbol, but it's not present anymore in $crawler->filter('body')->html()

There may be two solutions for this:

  • fix the problem in symfony/dom-crawler (ie: don't modify code inside <pre> tags?)
  • extract <body> tag content without dom crawler

@weaverryan any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<pre>product.stock < 15 </pre> seems to be an invalid html (tested on https://jsonformatter.org/html-validator)

Here we use code-block text but when it's code-block is xml < is encoded.

Copy link
Contributor

@nikophil nikophil Dec 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮

W3C validator says the same thing: < is invalid inside a <pre> whereas > is valid

I was always thinking <pre> would allow everything

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre

If you have to display reserved characters such as <, >, &, and " within the <pre> tag, the characters must be escaped using their respective HTML entity.

maybe the right thing to do would be to automate this replacement in code blocks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've provided a fix on the builder:
symfony-tools/docs-builder#145

actually the problem only occurred on .. code-block:: text

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 😃

javiereguiluz added a commit to symfony-tools/docs-builder that referenced this pull request Dec 30, 2022
This PR was merged into the main branch.

Discussion
----------

fix: escape special chars in code text

Hello there!

here is a fix for symfony/symfony-docs#17587

I had hard time understanding the problem was only occurring for code of type "text"!

cheers!

Commits
-------

3407885 fix: escape special chars in code text
@javiereguiluz
Copy link
Member

Thanks Antoine ... but I'm closing this one without merging because @nikophil fixed the underlying issue in the Symfony Docs Builder and we tagged a new version: https://github.com/symfony-tools/docs-builder/releases/tag/v0.18.10

I just updated it on symfony.com too, so this should be solved the next time that docs are rebuild.

Thanks to all reviewers too. Fixing this was a nice team effort! 💪

@alamirault
Copy link
Contributor Author

No problem, thank you @nikophil !

@alamirault alamirault deleted the hotfix/expression-language-example branch December 31, 2022 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants