Skip to content

Commit

Permalink
chore: update commonmark & html converters to use text
Browse files Browse the repository at this point in the history
also allow for content to be embedded
in an arbitrary level for datasets,
rather than eating the content
  • Loading branch information
tim-evans authored and colin-alexa committed Mar 21, 2024
1 parent a848b44 commit 62f1e94
Show file tree
Hide file tree
Showing 5 changed files with 1,786 additions and 618 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
AdjacentBoundaryBehaviour,
JSON,
SliceAnnotation,
compareAnnotations,
Annotation,
TextAnnotation,
} from "@atjson/document";

import OffsetSource, { DataSet, Table, ColumnType } from "../index";
Expand Down Expand Up @@ -106,13 +106,12 @@ export function convertHTMLTablesToDataSet(

if (headings.length) {
headings.sort(compareAnnotations).forEach((headCell, index) => {
if (index !== 0) {
doc.insertText(
headCell.start,
" ",
AdjacentBoundaryBehaviour.preserveBoth
);
}
doc.addAnnotations(
new TextAnnotation({
start: headCell.start,
end: headCell.end,
})
);

let slice = new SliceAnnotation({
...headCell,
Expand Down Expand Up @@ -154,8 +153,6 @@ export function convertHTMLTablesToDataSet(
);

tableRows.forEach((row) => {
doc.insertText(row.start, " ", AdjacentBoundaryBehaviour.preserveBoth);

let rowEntries: [string, { slice: string; jsonValue: JSON }][] = [];
doc
.where(
Expand All @@ -168,10 +165,11 @@ export function convertHTMLTablesToDataSet(
.sort(compareAnnotations)
.forEach((bodyCell, index) => {
if (index !== 0) {
doc.insertText(
bodyCell.start,
" ",
AdjacentBoundaryBehaviour.preserveBoth
doc.addAnnotations(
new TextAnnotation({
start: bodyCell.start,
end: bodyCell.end,
})
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/@atjson/renderer-commonmark/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ export default class CommonmarkRenderer extends Renderer {
}

*DataSet(): Generator<void, string, string[]> {
return "";
return (yield).join("");
}

*Table(
Expand All @@ -750,7 +750,7 @@ export default class CommonmarkRenderer extends Renderer {
return "";
}

const previousState = this.state;
const previousState = { ...this.state };
this.state.inlineOnly = true;

const dataSet = context.document.blocks.find(
Expand Down
4 changes: 2 additions & 2 deletions packages/@atjson/renderer-html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ export default class HTMLRenderer extends Renderer {
return `<pre>${codeSnippet}</pre>`;
}

*DataSet() {
return "";
*DataSet(): Iterator<void, string, string[]> {
return (yield).join("");
}

*Heading(heading: Block<Heading>) {
Expand Down
Loading

0 comments on commit 62f1e94

Please sign in to comment.