Skip to content

Commit

Permalink
use resources object instead of single unwieldy resource() function
Browse files Browse the repository at this point in the history
  • Loading branch information
idreyn committed Oct 5, 2021
1 parent 5ca21ad commit 9e9fe60
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pubpub/prosemirror-pandoc",
"version": "1.0.0",
"version": "1.1.0",
"description": "Convert between Prosemirror schemas and the Pandoc AST",
"main": "dist/index.js",
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/example/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ rules.toProsemirrorNode("RawInline", (node) => {
// These next rules for images don't use transform() because they're not inverses of each other --
// the Prosemirror->Pandoc direction wraps an Image in a Para to make it block-level

rules.toProsemirrorNode("Image", (node, { resource }) => {
rules.toProsemirrorNode("Image", (node, { resources }) => {
return {
type: "image",
attrs: {
url: resource(node.target.url),
url: resources.image(node.target.url),
altText: pandocInlineToPlainString(node.content),
// TODO(ian): is there anything we can do about the image size here?
},
Expand Down
5 changes: 3 additions & 2 deletions src/transform/fromPandoc/__tests__/fromPandoc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,13 +898,14 @@ describe("fromPandoc", () => {
{ type: "Str", content: "cool." },
],
},
rules
rules,
{ resources: { image: (x) => x.replace("pubpub", "duqduq") } }
).asNode()
).toEqual({
type: "image",
attrs: {
altText: "Very cool.",
url: "https://pubpub.org/logo.png",
url: "https://duqduq.org/logo.png",
},
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/transform/fromPandoc/fromPandoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ export const fromPandoc = (
config: Partial<FromPandocTransformConfig> = {}
): Fluent<ProsemirrorNode> => {
const {
resource = (x) => x,
resources = {},
useSmartQuotes = false,
prosemirrorDocWidth = 1000,
} = config;
const context: FromPandocTransformContext = {
ruleset,
resource,
resources,
useSmartQuotes,
count: makeCounter(),
transform: (element, parentContext = {}) =>
Expand Down
4 changes: 2 additions & 2 deletions src/transform/fromProsemirror/fromProsemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ export const fromProsemirror = (
ruleset: RuleSet<any>,
config: Partial<FromProsemirrorTransformConfig> = {}
): Fluent<PandocNode> => {
const { resource = (x) => x, prosemirrorDocWidth = 1000 } = config;
const { resources = {}, prosemirrorDocWidth = 1000 } = config;
const context: FromProsemirrorTransformContext = {
ruleset,
resource,
resources,
prosemirrorDocWidth,
count: makeCounter(),
transform: (element) => fromProsemirrorInner(element, context),
Expand Down
2 changes: 1 addition & 1 deletion src/transform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type TransformCallback<

// Options passed into the transform process in both directions
type SharedTransformConfig = {
resource: (input: string, context?: any) => string;
resources: Record<string, any>;
prosemirrorDocWidth: number;
};

Expand Down

0 comments on commit 9e9fe60

Please sign in to comment.