You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Wraps selected text in HTML comment tags (''.) If no text is selected, the cursor is placed between the same.
Directory Description
Wraps selected text in HTML comment tags (''.) If no text is selected, the cursor is placed between the same.
This action was made possible by @sylumer's Insert Highlight Action. You'll note, in fact - at least as of initial release - it includes his Script step, entirely unmodified (including the comments!)
JS
// Set up variables for prefix and suffixletstrPrefix;letstrSuffix;if(draft.getTemplateTag("WRAP")=="")
\{// No WRAP tag defined, so we must use PREFIX and SUFFIX// One of both of them may not be defined in which case the prefix // and/or suffix will be an empty string, allowing just for prefixes// or just for suffixes.strPrefix=draft.getTemplateTag("PREFIX");strSuffix=draft.getTemplateTag("SUFFIX");}else
\{// Wrap tag is defined, so prefix and suffix are identicalstrPrefix=draft.getTemplateTag("WRAP");strSuffix=strPrefix;}// Get selection range details from editorletrngSelected=editor.getSelectedRange();// Check if we are adding or undoing the insertion// If the text before and after is the prefix/suffix, extend the selectionletstrBeforeSelection=editor.getTextInRange(rngSelected\[0]-strPrefix.length,strPrefix.length);letstrAfterSelection=editor.getTextInRange(rngSelected\[0]+rngSelected\[1],strSuffix.length);if(strBeforeSelection==strPrefix&&strAfterSelection==strSuffix)
\{// Extend the range and update thje variable for the selection rangeeditor.setSelectedRange(rngSelected\[0]-strPrefix.length,strPrefix.length+rngSelected\[1]+strSuffix.length);rngSelected=editor.getSelectedRange();}// Get selection contentletstrSelection=editor.getSelectedText();if(strSelection.startsWith(strPrefix)&&strSelection.endsWith(strSuffix))
\{// Remove the selection and position the cursoreditor.setSelectedText(strSelection.substring(strPrefix.length,strSelection.length-strSuffix.length));rngSelected=editor.getSelectedRange();editor.setSelectedRange(rngSelected\[0]+rngSelected\[1],0);}else
\{//Add the selection// Replace the selection and position the cursor.if(!strSelection \||strSelection.length==0)
\{editor.setSelectedText(strPrefix+strSuffix);editor.setSelectedRange(rngSelected\[0]+strPrefix.length,0);}else
\{editor.setSelectedText(strPrefix+strSelection+strSuffix);editor.setSelectedRange(rngSelected\[0]+rngSelected\[1]+strPrefix.length+strSuffix.length,0);}}// Activate the editor for the selectioneditor.activate();
Install
The text was updated successfully, but these errors were encountered:
Updated
10112022-132913
https://davidblue.wtf/htmlcomment
Social
<script async="" src="https://telegram.org/js/telegram-widget.js?1" data-telegram-post="draftsapp/345" data-width="100%"></script> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>hey Drafts users! give this a whirl for me before I list it publicly, would ya? https://directory.getdrafts.com/a/2Dj
Before I list it publicly, I'd love it if any of y'all get a chance to try this HTML Comment Action.
Description
Wraps selected text in HTML comment tags (''.) If no text is selected, the cursor is placed between the same.
Directory Description
Wraps selected text in HTML comment tags (''.) If no text is selected, the cursor is placed between the same.
This action was made possible by @sylumer's Insert Highlight Action. You'll note, in fact - at least as of initial release - it includes his Script step, entirely unmodified (including the comments!)
JS
Install
The text was updated successfully, but these errors were encountered: