Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

〰 Add line for algorithms #251

Merged
merged 2 commits into from
Oct 22, 2023
Merged
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
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;
}
Loading