Skip to content

Commit

Permalink
feat: initial RTL support
Browse files Browse the repository at this point in the history
  • Loading branch information
SegaraRai committed Jun 16, 2024
1 parent 0aa9a1e commit 170fded
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 40 deletions.
8 changes: 5 additions & 3 deletions src/server/jsx/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function escapeHTMLComment(value: string): string {
.replaceAll("--", "--");
}

function renderProps(props: Readonly<Record<string, PropValue>>): string {
function renderAttributes(props: Readonly<Record<string, PropValue>>): string {
return Object.entries(props)
.filter(
([key, value]) =>
Expand Down Expand Up @@ -141,7 +141,9 @@ function isNoNewlineTag(tag: string): boolean {
export function render(node: Node, noNewlines = false): string {
switch (node[SYMBOL_NODE_TYPE]) {
case NODE_TYPE_SUBSTANTIAL: {
const { t: tag, p: props, c: children } = node;
const { t: tag, p: props } = node;
const children = node.p.children ? [node.p.children].flat() : node.c;

if (typeof tag === "string") {
if (!isValidTagProp(tag)) {
if (import.meta.env.DEV) {
Expand All @@ -155,7 +157,7 @@ export function render(node: Node, noNewlines = false): string {
return `<!--${escapeHTMLComment(String(props.content))}-->`;
}

const preamble = `<${tag}${renderProps(props)}`;
const preamble = `<${tag}${renderAttributes(props)}`;

return children.some((child) => child != null && child !== "")
? `${preamble}>${renderChildren(children, noNewlines || isNoNewlineTag(tag))}</${tag}>`
Expand Down
Loading

0 comments on commit 170fded

Please sign in to comment.