Skip to content

Commit

Permalink
〰 Add line for algorithms (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 authored Oct 22, 2023
1 parent 32ad820 commit 29fc03a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/myst-to-react/src/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { NodeRenderer } from '@myst-theme/providers';
import classNames from 'classnames';
import { Tooltip } from './components/index.js';
import { MyST } from './MyST.js';
import type { GenericNode } from 'myst-common';

type TableExts = {
rowspan?: number;
Expand Down Expand Up @@ -46,6 +47,7 @@ type BasicNodeRenderers = {
emphasis: NodeRenderer<spec.Emphasis>;
link: NodeRenderer<spec.Link>;
paragraph: NodeRenderer<spec.Paragraph>;
algorithmLine: NodeRenderer<GenericNode>;
break: NodeRenderer<spec.Break>;
inlineMath: NodeRenderer<spec.InlineMath>;
math: NodeRenderer<spec.Math>;
Expand Down Expand Up @@ -129,6 +131,17 @@ const BASIC_RENDERERS: BasicNodeRenderers = {
</p>
);
},
algorithmLine({ node }) {
// Used in algorithms
const style = {
paddingLeft: `${(node.indent ?? 0) + 2}rem`,
};
return (
<p className="line" style={style} data-line-number={node.enumerator}>
<MyST ast={node.children} />
</p>
);
},
break() {
return <br />;
},
Expand Down
1 change: 1 addition & 0 deletions styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
@import './tasklists.css';
@import './grid.css';
@import './hover.css';
@import './proof.css';
16 changes: 16 additions & 0 deletions styles/proof.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
p[data-line-number].line::before {
content: attr(data-line-number);
position: absolute;
left: 0;
font-family: monospace;
width: 1.25em;
text-align: right;
user-select: none;
color: gray;
overflow: hidden;
}

p.line {
position: relative;
margin: 0;
}

0 comments on commit 29fc03a

Please sign in to comment.