Mark
Highlight lines.
content.md
```jsfunction lorem(ipsum, dolor = 1) {// !markreturn dolor}function ipsum(lorem, dolor = 1) {// !mark(1:2) goldconst sit = lorem == null ? 0 : lorem.sitdolor = sit - amet(dolor)// !mark[/sit/] pinkreturn sit ? consectetur(lorem) : []}```
function lorem(ipsum, dolor = 1) {return dolor}function ipsum(lorem, dolor = 1) {const sit = lorem == null ? 0 : lorem.sitdolor = sit - amet(dolor)return sit ? consectetur(lorem) : []}
Implementation
For the block annotations: implement the Line
component, and for the inline annotations: implement the Inline
component. Use the annotation.query
as an optional color for the mark.
code.tsx
import { AnnotationHandler, InnerLine } from "codehike/code"const mark: AnnotationHandler = {name: "mark",Line: ({ annotation, ...props }) => {const color = annotation?.query || "rgb(14 165 233)"return (<divclassName=""style={{borderLeft: "solid 2px transparent",borderLeftColor: annotation && color,backgroundColor: annotation && `rgb(from ${color} r g b / 0.1)`,}}><InnerLine merge={props} className="" /></div>)},Inline: ({ annotation, children }) => {const color = annotation?.query || "rgb(14 165 233)"return (<spanclassName=""style={{outline: `solid 1px rgb(from ${color} r g b / 0.5)`,background: `rgb(from ${color} r g b / 0.13)`,}}>{children}</span>)},}
Pass it to the handlers
prop of the Pre
component.
code.tsx
async function Code({ codeblock }: { codeblock: RawCode }) {const highlighted = await highlight(codeblock, "github-dark")return <Pre code={highlighted} handlers={[mark]} />}
Make it better
Some ideas to improve the mark annotation:
- Mix it with the
Focus annotation