Mkdocs material LaTeX not rendering in instant mode - mkdocs

I am trying to use KaTeX in Mkdocs Material theme. When the 'instant mode' is off, everything works fine. However, in the instant mode, only the KaTeX in the page I enter first is rendered, while the rest KaTeX (loaded when clicked on internal links) remain in plain text with the delimiters \( and \). To render these KaTeX, I have to refresh the whole page. How can I fix this?
I tried 3 pieces of JavaScript, but all of them behaves as described above.
1.
document.addEventListener('DOMContentLoaded', function() {
renderMathInElement(document.body, {
delimiters: [
{left: '\\[', right: '\\]', display: true},
{left: '$$', right: '$$', display: true},
{left: '\\(', right: '\\)', display: false},
{left: '$', right: '$', display: false},
]
});
});
document.onreadystatechange = function () {
if (document.readyState == "complete") {
renderMathInElement(document.body, {
delimiters: [
{left: '\\[', right: '\\]', display: true},
{left: '$$', right: '$$', display: true},
{left: '\\(', right: '\\)', display: false},
{left: '$', right: '$', display: false},
]
});
}
}
https://facelessuser.github.io/pymdown-extensions/extensions/arithmatex/#loading-katex
Also, the Arithmatex extension is on. In mkdocs.yml:
markdown_extensions:
- pymdownx.arithmatex:
generic: true

MathJax 3 handles this automatically and should work with Material's instant loading out-of-the-box. See https://squidfunk.github.io/mkdocs-material/reference/mathjax/#arithmatex for setup instructions.
If you wish to use another typesetting library with instant loading which doesn't catch location changes, you can listen for them yourself and re-trigger typesetting by adding some additional JavaScript:
app.location$.subscribe(function() {
// instant loading finished
})

Related

Does React automatically remove the CSS applied to a component once it is unmounted?

I am using tailwind css and have added some custom animations in tailwind.config.cjs file. I have used this animation in Login component.Once user logs in he will be redirected to the home page it means login component unmounts, once it unmounts do I need to remove the animation applied to the login component manually using useEffect or it will be removed automatically. I have read that you should remove animations manually, but I am not sure. one more question When component unmounts it removes all the CSS applied to it right?
I would really appreciate it if someone could explain this to me in brief.
This is how my tailwind.config.cjs file looks-
module.exports = {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
darkMode: "class",
theme: {
extend: {
keyframes: {
changeBgDark: {
"0%, 100%": { "background-image": "linear-gradient(to left, #4c1d95,#0284c7,blue)",
"background-size":"200%",
"background-position":"right"
},
"50%": { "background-image": "linear-gradient(to right,blue,#0284c7,#4c1d95)",
"background-size":"200%",
"background-position":"left"},
},
changeBgLight: {
"0%, 100%": { "background-image": "linear-gradient(to left, #6d28d9,#0d9488,#06b6d4)",
"background-size":"200%",
"background-position":"right"
},
"50%": { "background-image": "linear-gradient(to right,#06b6d4,#0d9488,#6d28d9)",
"background-size":"200%",
"background-position":"left"},
}
},
animation: {
changeBgLight: "changeBgLight 5s ease-in-out infinite",
changeBgDark: "changeBgDark 5s ease-in-out infinite"
},
},
},
plugins: [],
};
React doesn't provide this type of function or anything . It would help if you did that manually way.

monaco-editor - resize property causes editor popups to be hidden

I am using deltaDecorations to show errors in my editor.
here is my code: https://gist.github.com/dinager/41578bd658b60cc912a6023f80431810
Here is the result:
I am trying to add resize property to the editor by adding to the style
resize: both;overflow: auto;
But then the hover message is partly hidden by the edges of the editor
As you can see in below attached image - the editor can resize now (bottom right), but the hover message is partly hidden
How can I add resize property to not hide elements?
Another question: can I make the hover message float inside the editor, meaning if it's at the top line it should float to the bottom, if at the side of the editor float to the middle, etc..
Attaching the code adding the markerDecorations (exists also in the gist link at the top):
this.markerDecorations = codeEditor.deltaDecorations(this.markerDecorations, [
{
range: new monaco.Range(pos.startLine, pos.startColumn, pos.endLine, pos.endColumn),
options: {
className: 'squiggly-error',
minimap: {
color: { id: 'minimap.errorHighlight' },
position: monaco.editor.MinimapPosition.Gutter,
},
overviewRuler: {
color: { id: 'editorOverviewRuler.errorForeground' },
position: monaco.editor.OverviewRulerLane.Full,
},
stickiness: monaco.editor.TrackedRangeStickiness.AlwaysGrowsWhenTypingAtEdges,
zIndex: 1,
hoverMessage: { value: parseResponse.error, isTrusted: false },
},
},
]);
solved it by adding fixedOverflowWidgets: true on monaco.editor.create options.
this.editor = monaco.editor.create(el, {
// ...
fixedOverflowWidgets: true
});

Is there any option in intro.js to make highlighted text or image clear

I am trying to implement intro.js in ionic 4 but the highlighted text is not visible
enter image description here
here how i implemented the code in angular 7.
intro() {
let intro = introJs.introJs();
intro.setOptions({
exitOnOverlayClick: false,
showStepNumbers: false,
showBullets: false,
overlayOpacity: 0.8,
doneLabel: "GOT IT",
nextLabel: "GOT IT",
steps: [
{
element: '#search-img',
intro: "Search here by accounts, contacts, etc.",
position: 'top',
}, {
element: '#search-text',
intro: "Search here by accounts, contacts, etc.",
position: 'top',
},
{
element: '#search-box',
intro: "Search here by accounts, contacts, etc.",
position: 'middle',
},
{
element: '#profile',
intro: "Click on profile icon to view your DPN account & saved
list",
position: 'bottom',
floatVArrow: 'right'
}
]
});
intro.start();
}
You can achieve this by using the highlightClass attribute for that particular step so that the step points to a class (I called it .my-bespoke-class) where you use CSS to do whatever you like to the highlight eg changing the opacity or colour.
I would need to check but I am pretty sure you can change the overlayOpacity for a step too (you certainly can in Shepherd).
let intro = introJs();
intro.setOptions({
exitOnOverlayClick: false,
showStepNumbers: false,
showBullets: false,
overlayOpacity: 0.8,
doneLabel: "GOT IT",
nextLabel: "GOT IT",
steps: [
{
element: '#search-text',
intro: "Search here by accounts, contacts, etc.",
position: 'top',
highlightClass: '.my-bespoke-class',
overlayOpacity: '1'
}
]
});
intro.start();
#search-text{
width: 300px:
margin: 10px auto;
}
.my-bespoke-class{
background: orange;
font-size: 100px;
}
<link href="https://cdn.jsdelivr.net/npm/intro.js-mit#3.0.0/introjs.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/intro.js-mit#3.0.0/intro.min.js"></script>
<html>
<body>
<div id="search-text">This is the target element</div>
</body>
</html>
Further information can be found in the official docs which you can find at https://introjs.com/docs/

Ckeditor allowedContent for html tag

I am using Ckeditor as rich editor for text input in the Chrome browser. I also have added some html id tag for easy parsing by bs4 after the system getting the data.
The following is my setting in the html:
CKEDITOR.replace( 'editor', {
toolbar : 'Basic',
uiColor : '#9AB8F3',
height : '70%',
startupShowBorders: false,
})
And in the config.js:
config.toolbarGroups = [
{ name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ] },
{ name: 'links' },
{ name: 'insert' },
{ name: 'forms' },
{ name: 'tools' },
{ name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
{ name: 'others' },
'/',
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
{ name: 'styles' },
{ name: 'colors' },
{ name: 'about' }
];
// Remove some buttons provided by the standard plugins, which are
// not needed in the Standard(s) toolbar.
config.removeButtons = 'Underline,Subscript,Superscript';
// Set the most common block elements.
config.format_tags = 'p;h1;h2;h3;pre';
// Simplify the dialog windows.
config.removeDialogTabs = 'image:advanced;link:advanced';
config.allowedContent = True;
};
Although I have already followed the instruction to allow all html tag content to be preserved with config.allowedContent = *; in the config.jd. However, it seems not working as I got the following results when getting data (by CKEDITOR.instances.editor.getData()):
<span style='font-size:11.0pt;'> content </span>
instead of this that I want:
<span id="news_content" style='font-size:11.0pt;'> content </span>
In other words, it still strips out all the html tag I added.
When I checked the source code, I found that the same textarea content was produced twice with the one with the tag being put in hidden format, i.e.,
<textarea name="editor" id="editor" rows="100" cols="40" style="visibility: hidden; display: none;">
And the editor produces another version in the real textarea that allows me to edit. However, this is useless because all the html tags are stripped there.
So, my question is, how to preserve the html tag in the real textarea so that I can parse the html with id tags after editing and submission. Could anyone advise on this? Thanks a lot.
I may not be able to answer my own question, but I like to share my solution with those encountering similar situation.
In short, finally I give up using ckeditor or any plug-in editor as many of them will strip off the html tag, which is essential to me in the subsequent process.
Thanks to html5, my solution is using editable div. The setting is very simple as below:
css:
#my-content {
box-shadow: 0 0 2px #CCC;
min-height: 150px;
overflow: auto;
padding: 1em;
margin: 5px;
resize: vertical;
outline: none;
}
html:
<div id="my-content" class="editable" style="width:900px; height:400px; text-overflow: ellipsis; overflow-y: scroll;"></div>
js script:
$('.editable').each(function(){
this.contentEditable = true;
});
So far, I am happy with it, it shows what exactly the html code showing and preserve all the tags I added. The only downside is it does not provide any toolbar for format editing. My solution is to make one for it, and via the following link you can get a very good tutorial as to making a toolbar with a ready-to-use demo as illustration.
https://code.tutsplus.com/tutorials/create-a-wysiwyg-editor-with-the-contenteditable-attribute--cms-25657
Hope this helps.

TinyMCE and HTML5 form validation

I'm using TinyMCE in a Rails application. In my form, I have a "description" field with TinyMCE and this field is mandatory for the form validation.
But when I try to submit my form, I can't, because of the HTML5 form validation. My browser (Chrome and Firefox) tells me that the field is empty. And I have another problem. When Chrome displays the dialog for the empty field, it appears on the top of my page, not near my form field.
FF show up a bubble for required fileld but at wrong place, Chrome throws an error because it can't find field to show bubble.. So my solution is disable display:none style set by TinyMCE and reduce the field size and make its visibility hidden. this way browser will show bubble next to this field as this field is next to TinyMCE editor user will know what required field is missing.
textarea.tinymce {
background: transparent;
border: none;
box-shadow: none;
display: block !important;
height: 0;
resize: none;
width: 0;
visibility: hidden;
}
I used the "oninit" option in the textareas and worked:
oninit: function(editor) {
$currentTextArea.closest('form').bind('submit invalid', function() {
editor.save();
});
}
You could try to use onChange event, but it doesn't work properly in Firefox.
My complete code:
$('textarea.tinymce').each(function(){
var options = {
theme : "advanced",
skin : "cirkuit",
plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template", theme_advanced_buttons1 :"formatselect,fontsizeselect,forecolor,|,bold,italic,strikethrough,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,|,link,unlink,|,spellchecker",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_buttons4 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true
},
$this = $(this);
// fix TinyMCE bug
if ($this.is('[required]')) {
options.oninit = function(editor) {
$this.closest('form').bind('submit invalid', function() {
editor.save();
});
}
}
$this.tinymce(options);
});
I took #lucaswxp code and changed it a bit, because Firefox was throwing an error ($this.is not a function, if I recall it correctly).
Also I changed the way it fires the code from:
$this.tinymce(options);
to:
tinymce.init(options);
Full code:
$(window).load(function() {
var options = {
selector: 'textarea',
skin: "lightgray"
},
$this = $(this);
// fix tinymce bug
if ($this.is('[required]')) {
options.oninit = function(editor) {
$this.closest('form').bind('submit, invalid', function() {
editor.save();
});
}
}
tinymce.init(options);
});
Many thanks to the creator, it worked like wonder :)