Skip to content

Commit

Permalink
fix(frontend): replace markdown with html when update ES (#179) (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelB committed Nov 17, 2020
1 parent 25f3143 commit 6fef358
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
1 change: 1 addition & 0 deletions targets/frontend/src/components/editor/CodeEditor.js
Expand Up @@ -14,6 +14,7 @@ export default function CodeEditor({ onChange, value }) {
theme="github"
name="EditJsonContent"
setOptions={{
useWorker: false,
wrap: true,
}}
editorProps={{ $blockScrolling: true }}
Expand Down
49 changes: 31 additions & 18 deletions targets/frontend/src/lib/preview/glossary.js
Expand Up @@ -23,25 +23,38 @@ export function addGlossary(entries, htmlContent) {
let idHtmlContent = htmlContent;

let glossary = [];
entries.forEach(({ abbrs, definition, title, variants }) => {
glossary = glossary.concat(
[title, ...variants].map((term) => ({
definition,
pattern: new RegExp(
`${startTag}${wordBoundaryStart}(${term})${wordBoundaryEnd}${endTag}`,
"gi"
),
term,
}))
);
if (abbrs) {
glossary.push({
definition,
pattern: new RegExp(`${startTag}\\b(${abbrs})\\b${endTag}`, "g"),
term: abbrs,
});
entries.forEach(
({
abbreviations: abbreviationsRaw,
definition,
term,
variants: variantsRaw,
}) => {
const abbreviations = JSON.parse(abbreviationsRaw);
const variants = JSON.parse(variantsRaw);

glossary = glossary.concat(
[term, ...variants].map((term) => ({
definition,
pattern: new RegExp(
`${startTag}${wordBoundaryStart}(${term})${wordBoundaryEnd}${endTag}`,
"gi"
),
term,
}))
);

if (abbreviations.length) {
for (const word of abbreviations) {
glossary.push({
definition,
pattern: new RegExp(`${startTag}\\b(${word})\\b${endTag}`, "g"),
term: word,
});
}
}
}
});
);

// we make sure that bigger terms are replaced first
glossary.sort((previous, next) => {
Expand Down
6 changes: 5 additions & 1 deletion targets/frontend/src/pages/api/preview.js
Expand Up @@ -56,7 +56,11 @@ export default async function (req, res) {
});
res.json({ message: "doc updated!" });
} catch (response) {
console.error(response.body.error);
if (response.body) {
console.error(response.body.error);
} else {
console.error(response);
}
res.status(response.statusCode).json({ message: response.body.error });
}
}
Expand Down
4 changes: 2 additions & 2 deletions targets/frontend/src/pages/contenus/[id].js
Expand Up @@ -52,7 +52,7 @@ mutation updateDocument($cdtnId: String!, $metaDescription: String!, $title: Str
}
}`;

export function DocumentsPage() {
export function DocumentPage() {
const router = useRouter();

const [result] = useQuery({
Expand Down Expand Up @@ -148,4 +148,4 @@ export function DocumentsPage() {
);
}

export default withCustomUrqlClient(withUserProvider(DocumentsPage));
export default withCustomUrqlClient(withUserProvider(DocumentPage));

0 comments on commit 6fef358

Please sign in to comment.