Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
code-markers
Advanced tools
"After-the-fact" text markers for code blocks. Your code is already highlighted (like with hljs: fast, shiki: thorough, others), add some markers to it. This won't add syntax highlighting, but it will add some extra information to your code blocks.
code-markers
🖌️
Text and line markers for code blocks.
code-markers
on npmjs.org »
Contents:
What?
•
Install
•
Usage
•
Todo
•
Related
•
🤠
"After-the-fact" text markers for code blocks.
Your code is already highlighted (like with hljs), add some markers to it. Demonstrate changes, add emphasis, etc.
This won't add syntax highlighting, but it will add some extra information to your code blocks.
No Shadow DOM required. Bring your own styles.
Depends. If you just want the custom HTML element, get the ./dist/code-markers-elem.js
file to the browser and you can use the <code-markers>
element.
This may be easiest by npm
installing and relying on a bundler to build the file into your project. Node.js usage is the same:
npm install code-markers
Two ways: a custom HTML element and a JS function.
<code-markers>
custom HTML elementIn the browser, markup some code blocks by wrapping them in a <code-markers>
element.
<code-markers mark="{1-10,12,red}" ins="'blue'" del="/green|grey/">
<pre><code class="language-js hljs">
<span class="hljs-keyword">...</span></code></pre>
</code-markers>
Running the demo provides a good example:
npm install
npm run demo
localhost:8000/demo.html
in your browsermark
- vanilla <mark>
element wrapping and .mark
class (for lines)ins
- <mark class="ins">
and .ins
class (for lines)del
- <mark class="del">
and .del
class (for lines)Search and mark:
"foo"
or "'bar'"
"/foo/"
(always global)Mark lines:
"42"
"5-9"
Sets of values:
"{1,5-9 ,foo, 'bar',/baz/}"
element.markCode()
If the pre > code
block is already highlighted and the <code>
element already has the hljs
class, code marks will automatically be added. This is recommended as it's the fastest and most reliable.
Otherwise, you can call the markCode()
method on the <code-markers>
element to mark the code after highlighting is applied. Further, you don't have to have highlighting! Marks can be applied to any pre > code
block.
<script>
hljs.highlightAll()
window.addEventListener('load', () => {
const codeMarkers = document.querySelectorAll('code-markers')
codeMarkers.forEach(codeMarker => {
codeMarker.markCode()
})
})
</script>
code-markers mark {
padding: 0 0.2em;
}
code-markers mark.del {
background-color: #ebb;
text-decoration: line-through;
}
code-markers mark.ins {
background-color: #beb;
text-decoration: underline;
}
code-markers .code-line {
display: inline-block;
width: 100%;
}
code-markers .code-line.mark {
background-color: lightgoldenrodyellow;
}
code-markers .code-line.del {
background-color: lightcoral;
}
code-markers .code-line.ins {
background-color: lightblue;
}
markCode(code, options)
JS functionConfigurable JS funciton to mark a string code block. Used by the <code-markers>
element.
This function can be used in Node.js or the browser. This means you can add these markers as a part of your server rendering pipeline.
import { markCode } from 'code-markers'
markCode(
'<pre><code class="language-js hljs"><span class="hljs-', //...
{ mark: "{1-10,12,'red'}", ins: 'blue', del: '/green|grey/' },
)
code
- string of code to markoptions
- object with mark
, ins
, and del
properties
line:phrase
mark
, ins
, and del
are supportedElement attribute values parsed with fancy-value-parser
API inspired by expressive-code/plugin-text-markers
Thanks for scrolling, here's another .gif
FAQs
"After-the-fact" text markers for code blocks. Your code is already highlighted (like with hljs: fast, shiki: thorough, others), add some markers to it. This won't add syntax highlighting, but it will add some extra information to your code blocks.
We found that code-markers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.