I have a text that contains both C# and HTML code. I process this text with the Html.Raw method, and also use the highlight.js library to highlight the parts of the code. However, because the HTML tags are processed and converted to text by the Raw method, they are not processed by the highlight.js library. How can I solve this issue?
Related
I'm using CKEditor5 and trying to make the Mention plugin work together with the Markdown plugin. Currently, adding a #mention works but it is exported simply as #mention by editor.getData(), and instanciating an editor with data = '#mention' will not lead the package to parsing this data as a mention in the editor.
Ideally I'd like to have an escaped markdown inline block such as {objectName[objectId]} as the data input, which would then be upcast to the model as a MentionAttribute. For downcasting, one would need to find these MentionAttributes and downcast them to the correct syntax.
I have no clue how to do this, I am new to CKEditor5 the architecture of the package is complex and it can be hard to add customization. I know that there are upcast and downcast converters I can create, but I couldn't find anything for matching text and inserting it into the model.
Does anyone know how I could achieve this?
I was able to make this work by:
Using the Editor as a controlled component
Implementing a custom syntax for mentions in our markdown format
Passing markdown converted into HTML interpretable by the Model layer, including mention syntax used by the Mention plugin, to the data props of the Editor wrapper
On onChange events, pass the HTML converted back into markdown to the controller
I just started learning programming using MarkLogic.
I followed documentation, created "sample.sjs" file like in below.
https://docs.marklogic.com/guide/jsref/language#id_71272
xdmp.setResponseContentType("text/plain");
"hello"
How should I call this "sample.sjs" to display result in HTML?
Or should I better include HTML code inside "sample.sjs" file?
Your SJS code must construct whatever content you want to return to the caller, including HTML. The content returned by your module becomes the response data.
There's a bit more robust example using JSON instead of HTML, here:
https://developer.marklogic.com/learn/sjs/http
Background information :
A tool simulates IE behavior, instead of HTML for browser, it uses a special object which contains html segment<![CDATA[ HTML Here or JS here ]]>. The tool disabled the ajax call; however, the activeX works on that tool. In other words, HTML display in browser = special object display. No server side language (i.e. php) allowed.
Problem :
The object developed for that tool contains everything(html+css+js) in one single file. Then it makes developer difficult to manage changes. Currently, when I develop, I copied the HTML from <![CDATA[ All HTML or JS here ]]>; after I modified it , I copied the html file back to <![CDATA[ HTML Here or JS here ]]>. I want the object is more organized, for example: in the html segment of the object, just put something like <![CDATA[<javascript>require a.html<javascript> ]]> , then the content in a.html will be automatically placed in the object. Can you suggest any solution or any library for this problem?
ps: I didn't use requirejs before, it seems requirejs uses ajax call to include text file, is it possible that requirejs uses local path to include a file?
Thank you.
Partial solution to my problem: I used activeX to read the entire file, and used jQuery to set the file content to some html element. so the js will look like:
<![CDATA[
<script>var k = readfile(getAbsolutePath()+"\\a.html");
jQuery("#display").html(k);<script> ]]>
I think this solution is for my tool only; To make it work, some requirements:
1. can get the absolute path of the text/html file.
2. activeX works.
OK, now that I understood your problem.
Use
<iframe src="another_file.html">
That is probably the only way to load multiple html files without Ajax or PHP, as far as I know.
Per comment from prytsh, using an embed call should do the trick in HTML5:
You can try this by using jquery
//use this line in jquery
$("#id").load("trackingCode.html");
I am currently writing a program that uses AJAX to load a form for editing objects on a website. I have found a similar question at Loading script tags via AJAX, but it doesn't really satisfy the needs of the program.
The ajax returned is a pre-built set of elements in a form, and when certain areas are called, say, a TinyMCE textarea (which it is), it returns a set of script tags built into the text.
So my question is, is it possible to run through the script tags that have been put in the div and run them?
Plus, I want to avoid using jQuery as it could be running on any number of platforms.
Yes, you can add the incoming html and scripts to the dom, then search the dom for any script tags. You would then eval the scripts and could ignore any jQuery script tags if you wish.
However:
This sort of solution tends to be quite brittle.
It would be much better and more stable for you to modify the Ajax payload into separate html and javascript scripts. That way your Ajax handler would be able to handle them directly without trying to separate them.
Added
Re: how to send back the html and javascript parts: you can either make separate Ajax calls, or return an JSON object that includes both parts. Eg:
{"js": "<the js part of the response>",
"html": "<the html part of the respons>"}
Use a json library on your host system to take care of the issue of escaping any quotes or other json special characters in either the js or html values.
Returning both the html and js at once saves an Ajax call (which can be significant) and will usually simplify your code quite a bit vs two calls.
I use this technique in production and it works well.
Do you mean you return a js script from the ajax and want to run it??If so, you can use the eval function.
I wish to develop some kind of external API which will include users putting some nonstandard tags on their pages (which I will then replace with the correct HTML). For example:
<body>
...
...
<LMS:comments></LMS:comments>
...
...
...
</body>
Hoe can I target and replace the <LMS:comments></LMS:comments> part?
Just use getElementsByTagName as usual to get the element.
You cannot change the tag name, you will have to replace the entire element.
See http://jsfiddle.net/2vcjm/
You want to use regular expressions.
Take a look at this page to get started:
http://www.regular-expressions.info/brackets.html
That whole website is a great reference.
If your document is valid XHTML (as opposed to just HTML), you can use XSLT to parse it.
There are JavaScript XSLT libraries, such as Google's AJAXSLT.
Barring that, you will need to extract the relevant part of the DOM, take the value of "innerHTML" for the contents, and replace the custom tags using JavaScript's regex and replace() function.
However, this sort of processing is usually done server-side, by passing your custom "HTML+" through some sort of templating/enrichment engine (which will also use XSLT or HTML parsers or worst case regexes).