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

Removing repetitive $...$ katex spans #31

Merged
merged 4 commits into from
Jun 5, 2024
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
18 changes: 17 additions & 1 deletion app/cip/[slug]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ import { notFound } from 'next/navigation'
import Link from 'next/link'
import Badge from '@/components/Badge'
import Markdown from '@/components/Markdown'
import { JSDOM } from 'jsdom';


// Removing repetitive $...$ katex spans
function removeAriaHiddenSpans(html) {
const dom = new JSDOM(html);
const document = dom.window.document;

const spans = document.querySelectorAll('span[aria-hidden="true"]');
spans.forEach(span => {
span.classList.add('hidden');
});

return document.body.innerHTML;
}

async function getCipFromParams(slug) {
slug = `CIP-${slug.split('-')[1].padStart(4, '0')}`
Expand Down Expand Up @@ -48,6 +63,7 @@ function parseAuthors(authors) {

export default async function Cip({ params }) {
const cip = await getCipFromParams(params.slug)
const cleanedHtml = removeAriaHiddenSpans(cip.body.html);

return (
<div className="pt-24 md:pt-40 flex justify-center pb-12">
Expand Down Expand Up @@ -88,7 +104,7 @@ export default async function Cip({ params }) {
</div>

<div className="prose prose-invert lg:prose-xl mx-auto prose-code:px-2 prose-code:py-1 prose-code:rounded-md">
<Markdown content={cip.body.html } />
<Markdown content={cleanedHtml} />
</div>
</article>
</div>
Expand Down
18 changes: 17 additions & 1 deletion app/cps/[slug]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ import { allCPs } from 'contentlayer/generated'
import { notFound } from 'next/navigation'
import Link from "next/link"
import Badge from "@/components/Badge"
import Markdown from '@/components/Markdown'
import { JSDOM } from 'jsdom';

// Removing repetitive $...$ katex spans
function removeAriaHiddenSpans(html) {
const dom = new JSDOM(html);
const document = dom.window.document;

const spans = document.querySelectorAll('span[aria-hidden="true"]');
spans.forEach(span => {
span.classList.add('hidden');
});

return document.body.innerHTML;
}

async function getCpsFromParams(slug) {
const cps = allCPs.find((cps) => cps.slug === slug)
Expand Down Expand Up @@ -45,6 +60,7 @@ function parseAuthors(authors) {

export default async function Cps({ params }) {
const cps = await getCpsFromParams(params.slug)
const cleanedHtml = removeAriaHiddenSpans(cps.body.html);

return (
<div className="pt-24 md:pt-40 flex justify-center pb-12">
Expand Down Expand Up @@ -85,7 +101,7 @@ export default async function Cps({ params }) {
</div>

<div className="prose prose-invert lg:prose-xl mx-auto">
<div dangerouslySetInnerHTML={{ __html: cps.body.html }} />
<Markdown content={cleanedHtml} />
</div>
</article>
</div>
Expand Down
4 changes: 2 additions & 2 deletions contentlayer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export default makeSource({
contentDirPath: 'content',
documentTypes: [Cip, Cps, CipAnnex, CpsAnnex],
markdown: {
remarkPlugins: [remarkGfm, remarkComment, remarkMath],
remarkPlugins: [remarkMath, remarkGfm, remarkComment],
rehypePlugins: [
rehypeSlug,
[
Expand Down Expand Up @@ -271,4 +271,4 @@ export default makeSource({
rehypeKatex
],
},
})
})
Loading