Highlight html syntax inside string? - visual-studio-code

Is there a way (plugin, option, or tip and trick) to highlight html syntax in a js string?
My document is .JS file, in which I use strings containing html code. Is it possible highlight html syntaxe inside these strings?

You can use the extension es6-string-html
Note: You need to add a comment with the language in front of the multiline string

The extension that you suggested requires that you prefix your strings with a comment like /*html*/ or html. I'm working with Angular, and I didn't want to go through all my templates to prefix them, so I found this extension that does it automatically without prefixes:
https://marketplace.visualstudio.com/items?itemName=natewallace.angular2-inline
It is included in the Angular Essentials package by John Papa:
https://marketplace.visualstudio.com/items?itemName=johnpapa.angular-essentials

For Vue try Vue Inline Template:
https://marketplace.visualstudio.com/items?itemName=faisalhakim47.vue-inline-template

Related

How do I format a string for use in an inline script rendered as HTML?

I have the following properties string
GET 50% OFF ANY M'EDIUM OR L"AR"GE PIZZA!
I am using it in an HTML onclick markup like so
onclick="trackPromoCta(encodeURI(${properties.ctaTwoTextRight # context='text'}));"
However this outputs invalid html. I tried #context of scriptString and that escapes but only for inside JavaScript not for inside HTML markup. I tried all of the other options as well and none of them actually escape special characters for rendering HTML.
I saw someone once use a #format to search the string for these characters and escape them for HTML but I can't find out how to use #format to do this.
The expected output should be
onclick="trackPromoCta(encodeURI('GET 50% OFF ANY M'EDIUM OR L"AR"GE PIZZA!'));"
Take a look at the HTL spec for display context: https://github.com/Adobe-Marketing-Cloud/htl-spec/blob/master/SPECIFICATION.md#121-display-context
What you need is scriptString since your string property will eventually be used as a javascript string literal.
${properties.jcr:title # context='scriptString'} <!--/* Applies JavaScript string escaping */-->
Also, you need to enclose your HTL expression with single quotes, for example:
var str = '${'this is a js string literla' # context='scriptString'}'
The HTL code for you specific example would be:
onclick="trackPromoCta(encodeURI('${properties.ctaTwoTextRight # context='scriptString'}'));"
The #context value "text", "html" or "attribute" will return encoded values in your resulting html. As per documentation too, text encodes all HTML special characters.
If you go through your html's code using "View Page Source" and not via "Inspect element of developer tools". You will see the expected outcome.
onclick="trackPromoCta(encodeURI('GET 50% OFF ANY M'EDIUM OR L"AR"GE PIZZA!'));"
Reference:
https://helpx.adobe.com/experience-manager/htl/using/expression-language.html

HTML entities in attributes with tinymce

When I have doble marks encoded in my HTML attributes, tinymce breaks that attributes.
For example:
data-value="ab&quote;----&quote;"> will be seen in source code: <div data-type="more-posts" data-value="ab">Hello</div>
http://codepen.io/anon/pen/MKYrbJ
How can I fix this?
If you would have real double quotes here your HTML would not be valid anymore because attributes use them.
It will be best do handle those when you save that content to your database.
You could replace them with single quotes - those wouldn't break the markup.

Literal HTML markup doxygen

Is it possible to use literal HTML markup in doxygen. By literal i mean
I want this tag here and do not touch it
Background: I want to have this[1] in my documentation, but doing so requires a custom div box, and doxygen breaks it.
[1] \subparagraph{} equivalent in html
I found that \htmlonly does the trick

regex_replace to replace certain html tags

Is there a way to convert BR tags and/or DIV tags to new lines so it will format correctly when I use an in a mailto? I was thinking I should look for any P, DIV, and BR tags and replace them with a new line character. So anywhere there is a closing tag put the new line character and remove the opening tag. After I do the above I will remove the rest of the html with remove_html="1" but I want to keep the paragraph format.
I thought it can be done using regex_replace but I'm not sure how to write it. Anyone know?
Do not parse HTML files using regex, use HTML parser (HTML::TreeBuilder or something similar that can do in line changes) module, or in this case, even better use XSLT transformations.

with tinymce, how to convert an html tag into a different format

I want to convert an HTML tag that tinymce returns into a different format.
e.g.
The italics tag I want to convert to #i#
Is that possible with the editor itself?
During postback I strip all html tags, so I need it in a different safer format.
Add an onsubmit call to your form and use a simple javascript function to string replace the html tags you want to keep.
A more constructive method that might achieve what you want is to use the built in 'Valid elements' feature of tinymce. You can specify exactly which HTML tags you want to keep and it will strip out anything else. Plus it might be able to save you the step of stripping out the HTML yourself.
e.g.
valid_elements : "i,b,u",
http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/valid_elements