Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjosephprice committed Nov 21, 2024
2 parents 30d4990 + 21b7594 commit 6eab30b
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 176 deletions.
2 changes: 1 addition & 1 deletion __tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ exports[`export multiple Markdown renderers > renders plain markdown as React 1`
exports[`heading 1`] = `"<h2 class=\\"heading heading-2 header-scroll\\" align=\\"\\"><div class=\\"heading-anchor anchor waypoint\\" id=\\"example-header\\"></div><div class=\\"heading-text\\"><div id=\\"section-example-header\\" class=\\"heading-anchor_backwardsCompatibility\\"></div>Example Header</div><a aria-label=\\"Skip link to Example Header\\" class=\\"heading-anchor-icon fa fa-anchor\\" href=\\"#example-header\\"></a></h2>"`;
exports[`image 1`] = `"<span aria-label="Image" class="img lightbox closed" role="button" tabindex="0"><span class="lightbox-inner"><img src="http://example.com/image.png" width="auto" height="auto" title="" class="img " alt="Image" loading="lazy"></span></span>"`;
exports[`image 1`] = `"<span aria-label="Expand image" class="img lightbox closed" role="button" tabindex="0"><span class="lightbox-inner"><img src="http://example.com/image.png" width="auto" height="auto" title="" class="img " alt="Image" loading="lazy"></span></span>"`;
exports[`list items 1`] = `
"<ul>
Expand Down
1 change: 1 addition & 0 deletions __tests__/compilers/compatability.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { vi } from 'vitest';
import { render, screen } from '@testing-library/react';

import { mdx, migrate, compile, run } from '../../index';
import { migrate } from '../helpers';

describe('compatability with RDMD', () => {
it('compiles glossary nodes', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/components/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ exports[`Components > Embed 3`] = `"<div class="embed embed_hasImg"><a class="em
exports[`Components > Embed 4`] = `"<div class="embed "><a class="embed-link" href="https://www.nytimes.com/2020/05/03/us/politics/george-w-bush-coronavirus-unity.html" rel="noopener noreferrer" target="_blank"><div class="embed-body"><small class="embed-provider">nytimes.com</small><div class="embed-title">rdmd</div></div></a></div>"`;
exports[`Components > Image 1`] = `"<span aria-label="Bro eats pizza and makes an OK gesture." class="img lightbox closed" role="button" tabindex="0"><span class="lightbox-inner"><img src="https://files.readme.io/6f52e22-man-eating-pizza-and-making-an-ok-gesture.jpg" width="auto" height="auto" title="Pizza Face" class="img " alt="Bro eats pizza and makes an OK gesture." loading="lazy"></span></span>"`;
exports[`Components > Image 1`] = `"<span aria-label="Expand image" class="img lightbox closed" role="button" tabindex="0"><span class="lightbox-inner"><img src="https://files.readme.io/6f52e22-man-eating-pizza-and-making-an-ok-gesture.jpg" width="auto" height="auto" title="Pizza Face" class="img " alt="Bro eats pizza and makes an OK gesture." loading="lazy"></span></span>"`;
7 changes: 6 additions & 1 deletion __tests__/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { vi } from 'vitest';
import { run, compile } from '../index';
import * as rdmd from '@readme/markdown-legacy';
import { run, compile, migrate as baseMigrate } from '../index';

export const silenceConsole =
(prop: keyof Console = 'error', impl = () => {}) =>
Expand All @@ -20,3 +21,7 @@ export const execute = async (doc: string, compileOpts = {}, runOpts = {}) => {
const module = await run(code, runOpts);
return module.default;
};

export const migrate = (doc: string) => {
return baseMigrate(doc, { rdmd });
};
2 changes: 1 addition & 1 deletion __tests__/migration/emphasis.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { migrate } from '../../index';
import { migrate } from '../helpers';

describe('migrating emphasis', () => {
it('trims whitespace surrounding phrasing content (emphasis, strong, etc)', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/migration/html-comments.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { migrate } from '../../index';
import { migrate } from '../helpers';

describe('migrating html comments', () => {
it('migrates escaped html comments', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/migration/html-entities.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { migrate } from '../../index';
import { migrate } from '../helpers';

describe('migrating html entities', () => {
it('removes html entity spaces', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/migration/image.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { migrate } from '../../index';
import { migrate } from '../helpers';

describe('migrating images', () => {
it('compiles images', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/migration/link-reference.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { migrate } from '../../index';
import { migrate } from '../helpers';

describe('mdx migration of link references', () => {
it('compiles link references correctly', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/migration/magic-block.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { migrate } from '../../index';
import { migrate } from '../helpers';

describe('migrating magic blocks', () => {
it('compiles magic blocks without enough newlines', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/migration/tables.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { migrate } from '../../index';
import { migrate } from '../helpers';

describe('mdx migration of tables', () => {
it('compiles tables with newlines and inline code', () => {
Expand Down
2 changes: 1 addition & 1 deletion components/Image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const Image = (Props: ImageProps) => {

return (
<span
aria-label={alt}
aria-label={`${lightbox ? 'Collapse image' : 'Expand image'}`}
className={`img lightbox ${lightbox ? 'open' : 'closed'}`}
onClick={toggle}
onKeyDown={handleKeyDown}
Expand Down
5 changes: 2 additions & 3 deletions lib/mdastV6.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import * as rdmd from '@readme/markdown-legacy';
import migrationTransformers from '../processor/migration';

const migrationNormalize = (doc: string) => {
return doc.replaceAll(/^(<!--.*?)\\-->$/gms, '$1-->');
};

const mdastV6: any = (doc: string) => {
const mdastV6: any = (doc: string, { rdmd }) => {
const [_normalizedDoc] = rdmd.setup(doc);
const normalizedDoc = migrationNormalize(_normalizedDoc);

const proc = rdmd.processor().use(migrationTransformers);
const proc = rdmd.processor().use(migrationTransformers).data('rdmd', rdmd);

const tree = proc.parse(normalizedDoc);
proc.runSync(tree, normalizedDoc);
Expand Down
4 changes: 2 additions & 2 deletions lib/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import mdx from './mdx';
import mdastV6 from './mdastV6';

const migrate = (doc: string): string => {
return mdx(mdastV6(doc)).replaceAll(/&#x20;/g, ' ');
const migrate = (doc: string, { rdmd }): string => {
return mdx(mdastV6(doc, { rdmd })).replaceAll(/&#x20;/g, ' ');
};

export default migrate;
Loading

0 comments on commit 6eab30b

Please sign in to comment.