-
Notifications
You must be signed in to change notification settings - Fork 5
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
changed markdown parser #809
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import React from "react"; | ||
import Link from "next/link"; | ||
import ReactMarkdown from "react-markdown"; | ||
|
||
import { | ||
mapTimePeriodNameToSlug, | ||
|
@@ -11,7 +12,6 @@ import CiteButton from "components/shared/CiteButton"; | |
import { stylesheet, classNames } from "./SourceSetInfo.css"; | ||
import { classNames as utilClassNames } from "css/utils.css"; | ||
|
||
const markdownit = require("markdown-it")({ html: true }); | ||
const { container } = utilClassNames; | ||
|
||
// Only the time period has a sameAs field | ||
|
@@ -49,34 +49,22 @@ class SourceSetInfo extends React.Component { | |
}} | ||
/> | ||
<div className={classNames.bannerTextWrapper}> | ||
<h1 | ||
dangerouslySetInnerHTML={{ | ||
__html: markdownit.renderInline(set.name) | ||
}} | ||
className={classNames.bannerTitle} | ||
/> | ||
<h1 className={classNames.bannerTitle}> | ||
<ReactMarkdown | ||
source={set.name} | ||
allowedTypes={["emphasis"]} | ||
unwrapDisallowed | ||
/> | ||
</h1> | ||
</div> | ||
</div> | ||
<div | ||
<ReactMarkdown | ||
id="dpla-description" | ||
source={set.hasPart.find(item => item.name === "Overview").text} | ||
className={`${classNames.description} sourceSetDescription ${classNames.description} ${this | ||
.state.isOpen | ||
? classNames.open | ||
: ""}`} | ||
dangerouslySetInnerHTML={{ | ||
__html: markdownit.render( | ||
set.hasPart | ||
.find(item => item.name === "Overview") | ||
.text.replace( | ||
/https?:\/\/.*?\/primary-source-sets\/sources\//g, | ||
"sources/" | ||
) | ||
.replace( | ||
/https?:\/\/.*?\/primary-source-sets\/sets\//g, | ||
"/primary-source-sets/" | ||
) | ||
) | ||
}} | ||
/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you want to allow emphasis in the above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes and it is because all types are allowed by default. emphasis is specified in the cases where we only want emphasis to show up |
||
<div | ||
id="dpla-showmore" | ||
|
@@ -101,65 +89,67 @@ class SourceSetInfo extends React.Component { | |
Created By | ||
</h2> | ||
{set.author.map(author => | ||
<div | ||
<ReactMarkdown | ||
key={author.name} | ||
dangerouslySetInnerHTML={{ | ||
__html: markdownit.renderInline( | ||
author.name + ", " + author.affiliation.name | ||
) | ||
}} | ||
source={author.name + ", " + author.affiliation.name} | ||
allowedTypes={["emphasis"]} | ||
unwrapDisallowed | ||
/> | ||
)} | ||
</div> | ||
<div className={classNames.metadatum}> | ||
<h2 className={classNames.metadataHeader}> | ||
Time Period | ||
</h2> | ||
{extractTimePeriod(set.about).map((period, i, periods) => | ||
<span key={period}> | ||
<Link | ||
prefetch | ||
href={{ | ||
pathname: "/primary-source-sets", | ||
query: { | ||
timePeriod: mapTimePeriodNameToSlug(period) | ||
} | ||
}} | ||
> | ||
<a | ||
className={`link ${classNames.link}`} | ||
dangerouslySetInnerHTML={{ | ||
__html: markdownit.renderInline(period) | ||
<ul> | ||
{extractTimePeriod(set.about).map((period, i, periods) => | ||
<li key={period}> | ||
<Link | ||
prefetch | ||
href={{ | ||
pathname: "/primary-source-sets", | ||
query: { | ||
timePeriod: mapTimePeriodNameToSlug(period) | ||
} | ||
}} | ||
/> | ||
</Link> | ||
{i < periods.length - 1 && <br />} | ||
</span> | ||
)} | ||
> | ||
<a className={`link ${classNames.link}`}> | ||
<ReactMarkdown | ||
source={period} | ||
allowedTypes={["emphasis"]} | ||
unwrapDisallowed | ||
/> | ||
</a> | ||
</Link> | ||
</li> | ||
)} | ||
</ul> | ||
</div> | ||
<div className={classNames.metadatum}> | ||
<h2 className={classNames.metadataHeader}>Subjects</h2> | ||
{extractSubjects(set.about).map((subject, i, subjects) => | ||
<span key={subject}> | ||
<Link | ||
prefetch | ||
href={{ | ||
pathname: "/primary-source-sets", | ||
query: { | ||
subject: mapSubjectNameToSlug(subject) | ||
} | ||
}} | ||
> | ||
<a | ||
className={`link ${classNames.link}`} | ||
dangerouslySetInnerHTML={{ | ||
__html: markdownit.renderInline(subject) | ||
<ul> | ||
{extractSubjects(set.about).map((subject, i, subjects) => | ||
<li key={subject}> | ||
<Link | ||
prefetch | ||
href={{ | ||
pathname: "/primary-source-sets", | ||
query: { | ||
subject: mapSubjectNameToSlug(subject) | ||
} | ||
}} | ||
/> | ||
</Link> | ||
{i < subjects.length - 1 && <br />} | ||
</span> | ||
)} | ||
> | ||
<a className={`link ${classNames.link}`}> | ||
<ReactMarkdown | ||
source={subject} | ||
allowedTypes={["emphasis"]} | ||
unwrapDisallowed | ||
/> | ||
</a> | ||
</Link> | ||
</li> | ||
)} | ||
</ul> | ||
</div> | ||
</div> | ||
<div className={classNames.citeButton}> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just sanity checking - you don't want rendered markdown in breadcrumbs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm passing the title as-is and markdownifying it in the breadcrumbs module