-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
18 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"astro-portabletext": minor | ||
--- | ||
|
||
Feat: Unhandled `style` in `Block` component and unhandled `markType` in `Mark` component now throws an error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
--- | ||
import UnknownMark from "./UnknownMark.astro"; | ||
import { Mark, Props } from "../types"; | ||
import { throwError } from "../internal"; | ||
import { unknownMarkWarning } from "../warnings"; | ||
const { node, astroClass, ...props } = Astro.props; | ||
const { node, astroClass } = Astro.props as Props<Mark>; | ||
const attrs = { class: astroClass }; | ||
const markTypeIs = (markType: string) => markType === node.markType; | ||
const err = unknownMarkWarning(node.markType); | ||
--- | ||
|
||
{markTypeIs("code") ? ( | ||
<code {...attrs}><slot /></code> | ||
) : markTypeIs("em") ? ( | ||
<em {...attrs}><slot /></em> | ||
) : markTypeIs("link") ? ( | ||
<a href={node.markDef?.href} {...attrs}><slot /></a> | ||
<a href={(node as unknown as Mark<{ href: string }>).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} /> | ||
throwError(err) | ||
)} |