Skip to content

Commit

Permalink
fix: use markDef
Browse files Browse the repository at this point in the history
  • Loading branch information
theisel committed Jul 4, 2022
1 parent 7ca752d commit fcde082
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions component/components/Mark.astro
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
---
import type { PtMarkComponentProps, PortableTextMark } from '../types';
import UnknownMark from './UnknownMark.astro';
interface Link extends PortableTextMark {
href: string
}
const { node, astroClass, ...props } = Astro.props as PtMarkComponentProps
const { node, astroClass, ...props } = Astro.props
const attrs = { class: astroClass };
const markTypeIs = (markType: string) => markType === node.markType
---
{
markTypeIs('code') ? <code {...attrs}><slot /></code>
: markTypeIs('em') ? <em {...attrs}><slot /></em>
: markTypeIs('link') ? <a href={(node as Link).href} {...attrs}><slot /></a>
: markTypeIs('link') ? <a href={node?.markDef?.href} {...attrs}><slot /></a>
: markTypeIs('strike-through') ? <del {...attrs}><slot /></del>
: markTypeIs('strong') ? <strong {...attrs}><slot /></strong>
: markTypeIs('underline') ? <span style="text-decoration: underline;" {...attrs}><slot /></span>
: <UnknownMark node={node} astroClass={astroClass} {...props} />
}
}

0 comments on commit fcde082

Please sign in to comment.