Commit aa8995dc authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Render annotation markdown text to HTML when exporting to that format

parent b4857fe7
...@@ -14,6 +14,7 @@ import { ...@@ -14,6 +14,7 @@ import {
import { annotationDisplayName } from '../helpers/annotation-user'; import { annotationDisplayName } from '../helpers/annotation-user';
import { stripInternalProperties } from '../helpers/strip-internal-properties'; import { stripInternalProperties } from '../helpers/strip-internal-properties';
import { VersionData } from '../helpers/version-data'; import { VersionData } from '../helpers/version-data';
import { renderMathAndMarkdown } from '../render-markdown';
import { formatDateTime } from '../util/time'; import { formatDateTime } from '../util/time';
export type JSONExportContent = { export type JSONExportContent = {
...@@ -203,7 +204,7 @@ export class AnnotationsExporter { ...@@ -203,7 +204,7 @@ export class AnnotationsExporter {
</p> </p>
<table> <table>
<tbody> <tbody style={{ verticalAlign: 'top' }}>
<tr> <tr>
<td>Group:</td> <td>Group:</td>
<td>{groupName}</td> <td>{groupName}</td>
...@@ -233,12 +234,21 @@ export class AnnotationsExporter { ...@@ -233,12 +234,21 @@ export class AnnotationsExporter {
{annotations.map((annotation, index) => { {annotations.map((annotation, index) => {
const page = pageLabel(annotation); const page = pageLabel(annotation);
const annotationQuote = quote(annotation); const annotationQuote = quote(annotation);
const renderedComment = renderMathAndMarkdown(annotation.text);
// When the result of rendering the text's markdown is just a
// single paragraph, we fall back to the annotation text, to
// avoid extra margins added by some editors, like Google Docs
const comment =
renderedComment === `<p>${annotation.text}</p>`
? annotation.text
: renderedComment;
return ( return (
<article key={annotation.id}> <article key={annotation.id}>
<h2>Annotation {index + 1}:</h2> <h2>Annotation {index + 1}:</h2>
<table> <table>
<tbody> <tbody style={{ verticalAlign: 'top' }}>
<tr> <tr>
<td>Created at:</td> <td>Created at:</td>
<td> <td>
...@@ -273,7 +283,11 @@ export class AnnotationsExporter { ...@@ -273,7 +283,11 @@ export class AnnotationsExporter {
)} )}
<tr> <tr>
<td>Comment:</td> <td>Comment:</td>
<td>{annotation.text}</td> <td
dangerouslySetInnerHTML={{
__html: comment,
}}
/>
</tr> </tr>
{annotation.tags.length > 0 && ( {annotation.tags.length > 0 && (
<tr> <tr>
......
...@@ -291,6 +291,12 @@ ${formattedNow},John Doe,,http://example.com,My group,Annotation,,Annotation tex ...@@ -291,6 +291,12 @@ ${formattedNow},John Doe,,http://example.com,My group,Annotation,,Annotation tex
const annotations = [ const annotations = [
{ {
...baseAnnotation, ...baseAnnotation,
text: `This includes markdown
1. First item
2. Second item
**bold text** and [a link](https://example.com)`,
user: 'acct:jane@localhost', user: 'acct:jane@localhost',
tags: ['foo', 'bar'], tags: ['foo', 'bar'],
target: targetWithSelectors(quoteSelector('The quote')), target: targetWithSelectors(quoteSelector('The quote')),
...@@ -343,7 +349,7 @@ ${formattedNow},John Doe,,http://example.com,My group,Annotation,,Annotation tex ...@@ -343,7 +349,7 @@ ${formattedNow},John Doe,,http://example.com,My group,Annotation,,Annotation tex
</a> </a>
</p> </p>
<table> <table>
<tbody> <tbody style="vertical-align:top;">
<tr> <tr>
<td>Group:</td> <td>Group:</td>
<td>My group</td> <td>My group</td>
...@@ -373,7 +379,7 @@ ${formattedNow},John Doe,,http://example.com,My group,Annotation,,Annotation tex ...@@ -373,7 +379,7 @@ ${formattedNow},John Doe,,http://example.com,My group,Annotation,,Annotation tex
<article> <article>
<h2>Annotation 1:</h2> <h2>Annotation 1:</h2>
<table> <table>
<tbody> <tbody style="vertical-align:top;">
<tr> <tr>
<td>Created at:</td> <td>Created at:</td>
<td> <td>
...@@ -396,7 +402,14 @@ ${formattedNow},John Doe,,http://example.com,My group,Annotation,,Annotation tex ...@@ -396,7 +402,14 @@ ${formattedNow},John Doe,,http://example.com,My group,Annotation,,Annotation tex
</tr> </tr>
<tr> <tr>
<td>Comment:</td> <td>Comment:</td>
<td>Annotation text</td> <td>
<p>This includes markdown</p>
<ol>
<li>First item</li>
<li>Second item</li>
</ol>
<p><strong>bold text</strong> and <a href="https://example.com" target="_blank">a link</a></p>
</td>
</tr> </tr>
<tr> <tr>
<td>Tags:</td> <td>Tags:</td>
...@@ -408,7 +421,7 @@ ${formattedNow},John Doe,,http://example.com,My group,Annotation,,Annotation tex ...@@ -408,7 +421,7 @@ ${formattedNow},John Doe,,http://example.com,My group,Annotation,,Annotation tex
<article> <article>
<h2>Annotation 2:</h2> <h2>Annotation 2:</h2>
<table> <table>
<tbody> <tbody style="vertical-align:top;">
<tr> <tr>
<td>Created at:</td> <td>Created at:</td>
<td> <td>
...@@ -447,7 +460,7 @@ ${formattedNow},John Doe,,http://example.com,My group,Annotation,,Annotation tex ...@@ -447,7 +460,7 @@ ${formattedNow},John Doe,,http://example.com,My group,Annotation,,Annotation tex
<article> <article>
<h2>Annotation 3:</h2> <h2>Annotation 3:</h2>
<table> <table>
<tbody> <tbody style="vertical-align:top;">
<tr> <tr>
<td>Created at:</td> <td>Created at:</td>
<td> <td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment