Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions packages/base/markdown-file-def.gts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
extractFileReferenceUrls,
FRONTMATTER_PARSE_ERROR_SYMBOL,
identifyCard,
VirtualNetwork,
type FrontmatterParseError,
} from '@cardstack/runtime-common';
import MarkdownIcon from '@cardstack/boxel-icons/align-box-left-middle';
Expand All @@ -17,7 +16,6 @@ import {
containsMany,
field,
linksToMany,
virtualNetworkFor,
} from './card-api';
import MarkdownTemplate from './default-templates/markdown';
import {
Expand Down Expand Up @@ -497,11 +495,7 @@ export class MarkdownDef extends FileDef {
if (!this.content) {
return [];
}
return extractCardReferenceUrls(
this.content,
this.id ?? '',
virtualNetworkFor(this) ?? new VirtualNetwork(),
);
return extractCardReferenceUrls(this.content, this.id ?? '');
},
});

Expand All @@ -518,11 +512,7 @@ export class MarkdownDef extends FileDef {
if (!this.content) {
return [];
}
return extractFileReferenceUrls(
this.content,
this.id ?? '',
virtualNetworkFor(this) ?? new VirtualNetwork(),
);
return extractFileReferenceUrls(this.content, this.id ?? '');
},
});

Expand Down Expand Up @@ -629,16 +619,8 @@ export class MarkdownDef extends FileDef {
// `frontmatter.rawContent`, and the verbatim file is always served from
// the realm, so nothing is lost.
content: body,
cardReferenceUrls: extractCardReferenceUrls(
body,
url,
new VirtualNetwork(),
),
fileReferenceUrls: extractFileReferenceUrls(
body,
url,
new VirtualNetwork(),
),
cardReferenceUrls: extractCardReferenceUrls(body, url),
fileReferenceUrls: extractFileReferenceUrls(body, url),
};

// Boxel-specific frontmatter is namespaced under `boxel:`; generic
Expand Down
31 changes: 14 additions & 17 deletions packages/base/rich-markdown.gts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
extractFileReferenceUrls,
fieldSerializer,
relativeTo,
VirtualNetwork,
} from '@cardstack/runtime-common';
import { TrackedObject } from 'tracked-built-ins';
import { eq } from '@cardstack/boxel-ui/helpers';
Expand Down Expand Up @@ -62,22 +61,18 @@ export class RichMarkdownField extends FieldDef {
if (!rel) {
return '';
}
return typeof rel === 'string'
? (virtualNetworkFor(this)?.toURL(rel).href ?? rel)
: rel.href;
// `relativeTo` is already a canonical RRI; references resolve against it in
// RRI space (no VirtualNetwork).
return typeof rel === 'string' ? rel : rel.href;
}

/** Resolved absolute URLs of `:card[URL]` and `::card[URL]` references. */
/** Resolved canonical-RRI references of `:card[URL]` and `::card[URL]`. */
@field cardReferenceUrls = containsMany(StringField, {
computeVia: function (this: RichMarkdownField) {
if (!this.content) {
return [];
}
return extractCardReferenceUrls(
this.content,
this.refBaseUrl,
virtualNetworkFor(this) ?? new VirtualNetwork(),
);
return extractCardReferenceUrls(this.content, this.refBaseUrl);
},
});

Expand All @@ -97,11 +92,7 @@ export class RichMarkdownField extends FieldDef {
if (!this.content) {
return [];
}
return extractFileReferenceUrls(
this.content,
this.refBaseUrl,
virtualNetworkFor(this) ?? new VirtualNetwork(),
);
return extractFileReferenceUrls(this.content, this.refBaseUrl);
},
});

Expand Down Expand Up @@ -235,7 +226,10 @@ export class RichMarkdownField extends FieldDef {
{{! Preview has no CodeMirrorEditor, so the sticky mode selector
lives in its own docked bar above the rendered markdown. }}
<div class='rich-markdown-toolbar' data-test-markdown-toolbar>
<MarkdownEditorModeSelect @mode={{this._mode}} @onChange={{this.setMode}} />
<MarkdownEditorModeSelect
@mode={{this._mode}}
@onChange={{this.setMode}}
/>
</div>
<div class='rich-markdown-preview' data-test-markdown-preview>
<MarkdownTemplate
Expand All @@ -259,7 +253,10 @@ export class RichMarkdownField extends FieldDef {
@getCards={{context.getCards}}
>
<:leadingControls>
<MarkdownEditorModeSelect @mode={{this._mode}} @onChange={{this.setMode}} />
<MarkdownEditorModeSelect
@mode={{this._mode}}
@onChange={{this.setMode}}
/>
</:leadingControls>
</CodeMirrorEditor>
</CardContextConsumer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ import {
extractFileReferenceUrls,
fileNameFromUrl,
isCardErrorJSONAPI,
resolveRRIReference,
rri,
trimJsonExtension,
type VirtualNetwork,
} from '@cardstack/runtime-common';
import { markdownToHtml } from '@cardstack/runtime-common/marked-sync';

import CardRenderer from '@cardstack/host/components/card-renderer';

import type NetworkService from '@cardstack/host/services/network';
import type StoreService from '@cardstack/host/services/store';

import type {
Expand Down Expand Up @@ -70,14 +69,14 @@ interface RenderSlot {
typeName?: string; // present when state === 'unresolved'
}

function resolveUrl(
raw: string,
baseUrl: string | undefined,
virtualNetwork: VirtualNetwork,
): string {
function resolveUrl(raw: string, baseUrl: string | undefined): string {
try {
// Resolve in RRI space (no VirtualNetwork), the same way
// `extractCardReferenceUrls`/`extractFileReferenceUrls` resolve the refs
// that key `loadedCards`/`loadedFiles` — so a slot's resolved key matches
// the loaded instance's map key.
return trimJsonExtension(
virtualNetwork.resolveRRI(raw, baseUrl ? rri(baseUrl) : undefined),
resolveRRIReference(raw, baseUrl ? rri(baseUrl) : undefined),
);
} catch {
return trimJsonExtension(raw);
Expand Down Expand Up @@ -116,7 +115,6 @@ const DEFAULT_CARD_CONTEXT: Partial<CardContext> = {
};

export default class RenderedMarkdown extends Component<Signature> {
@service declare private network: NetworkService;
@service declare private store: StoreService;
@consume(CardContextName) declare private dynamicCardContext: CardContext;

Expand Down Expand Up @@ -163,7 +161,6 @@ export default class RenderedMarkdown extends Component<Signature> {
return extractCardReferenceUrls(
this.args.content,
this.args.cardReferenceBaseUrl ?? '',
this.network.virtualNetwork,
);
}

Expand All @@ -173,7 +170,6 @@ export default class RenderedMarkdown extends Component<Signature> {
return extractFileReferenceUrls(
this.args.content,
this.args.cardReferenceBaseUrl ?? '',
this.network.virtualNetwork,
);
}

Expand Down Expand Up @@ -277,11 +273,7 @@ export default class RenderedMarkdown extends Component<Signature> {
);
}

let resolvedUrl = resolveUrl(
rawUrl,
baseUrl,
this.network.virtualNetwork,
);
let resolvedUrl = resolveUrl(rawUrl, baseUrl);

if (refType === 'file') {
let file = filesByUrl.get(resolvedUrl);
Expand Down
Loading
Loading