Skip to content

Commit

Permalink
πŸ§‘πŸ»β€πŸ”¬ Slight improvements to chemical formulas (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 committed Jun 16, 2023
1 parent 0973ec3 commit 162c9ef
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-geese-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-demo': patch
---

Update types!
5 changes: 5 additions & 0 deletions .changeset/lovely-cups-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-to-react': patch
---

Update chemical formula parsing and presentation
5 changes: 5 additions & 0 deletions .changeset/serious-weeks-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@myst-theme/book': patch
---

Remove console.log
2 changes: 1 addition & 1 deletion packages/myst-demo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function MySTRenderer({
column?: boolean;
fullscreen?: boolean;
captureTab?: boolean;
TitleBlock?: (props: { frontmatter: PageFrontmatter }) => JSX.Element;
TitleBlock?: (props: { frontmatter: PageFrontmatter }) => JSX.Element | null;
numbering?: any;
className?: string;
}) {
Expand Down
7 changes: 4 additions & 3 deletions packages/myst-to-react/src/extensions/chemicalFormula.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import type { NodeRenderer } from '@myst-theme/providers';
* @returns ['H', '2', '0']
*/
function parseFormula(formula?: string) {
return [...(formula ?? '')].reduce((acc, letter) => {
return [...(formula ?? '')].reduce((acc, current) => {
const last = acc.pop();
const letter = current === '+' ? '⁺' : current === '-' ? '⁻' : current;
const isNumber = letter.match(/[0-9]/);
const lastIsNumber = last?.match(/[0-9]/);
if (isNumber) {
Expand All @@ -26,12 +27,12 @@ function parseFormula(formula?: string) {
export const ChemicalFormula: NodeRenderer = (node) => {
const parts = parseFormula(node.value);
return (
<code key={node.key} className="text-inherit">
<span key={node.key} className="text-inherit" aria-roledescription="Chemical Formula">
{parts.map((letter, index) => {
if (letter.match(/[0-9]/)) return <sub key={index}>{letter}</sub>;
return <span key={index}>{letter}</span>;
})}
</code>
</span>
);
};

Expand Down
1 change: 0 additions & 1 deletion themes/book/app/utils/loaders.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export async function getPage(

export async function getObjectsInv(): Promise<Buffer | null> {
const url = updateLink('/objects.inv');
console.log(url);
const response = await fetch(url).catch(() => null);
if (!response || response.status === 404) return null;
return response.buffer();
Expand Down

0 comments on commit 162c9ef

Please sign in to comment.