Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ggodlewski committed Jul 14, 2024
1 parent 1a9a353 commit 2e4d1e0
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 62 deletions.
6 changes: 3 additions & 3 deletions src/odt/OdtToMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ export class OdtToMarkdown {
const id = urlToFolderId(href);
const hash = getUrlHash(link.href);
if (id) {
href = 'gdoc:' + id;
href = 'gdoc:' + id + hash;
}

this.addLink(href + hash);
this.addLink(href);

const block = this.chunks.createNode('A', { href: href + hash });
const block = this.chunks.createNode('A', { href: href });
this.chunks.append(currentTagNode, block);
currentTagNode = block;

Expand Down
2 changes: 1 addition & 1 deletion src/odt/markdownNodesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export async function walkRecursiveAsync(node: MarkdownNode, callback: (node: Ma
const subCtx = await callback(node, ctx) || Object.assign({}, ctx);
for (let nodeIdx = 0; nodeIdx < node.children.length; nodeIdx++) {
const child = node.children[nodeIdx];
const retVal = await walkRecursiveAsync(child, callback, { ...subCtx, nodeIdx });
const retVal = await walkRecursiveAsync(child, callback, { ...subCtx, nodeIdx }, callbackEnd);
if (retVal && 'nodeIdx' in retVal && typeof retVal.nodeIdx === 'number') {
nodeIdx = retVal.nodeIdx;
}
Expand Down
3 changes: 2 additions & 1 deletion src/odt/postprocess/postProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ export async function postProcess(chunks: MarkdownNodes, rewriteRules: RewriteRu
convertCodeBlockParagraphs(chunks);
convertMathMl(chunks);

trimParagraphs(chunks);
await rewriteHeaders(chunks);
trimParagraphs(chunks);
addEmptyLinesAfterParas(chunks);
removeTdParas(chunks); // Requires: addEmptyLinesAfterParas

mergeTexts(chunks);
await rewriteHeaders(chunks);

mergeParagraphs(chunks);
unwrapEmptyPre(chunks);
Expand Down
56 changes: 50 additions & 6 deletions src/odt/postprocess/rewriteHeaders.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,60 @@
import {walkRecursiveAsync} from '../markdownNodesUtils.ts';
import {MarkdownNodes} from '../MarkdownNodes.ts';
import {MarkdownNodes, MarkdownTextNode} from '../MarkdownNodes.ts';

export async function rewriteHeaders(markdownChunks: MarkdownNodes) {
await walkRecursiveAsync(markdownChunks.body, async (chunk) => {
let inPre = false;
await walkRecursiveAsync(markdownChunks.body, async (chunk, ctx: { nodeIdx: number }) => {
if (chunk.isTag && 'PRE' === chunk.tag) {
inPre = true;
}

if (inPre) {
if (chunk.isTag) {
for (let j = chunk.children.length - 1; j >= 0; j--) {
const child = chunk.children[j];
if (child.isTag && child.tag === 'BOOKMARK/') {
chunk.children.splice(j, 1);
break;
}
}
}
}

if (chunk.isTag && ['H1', 'H2', 'H3', 'H4'].includes(chunk.tag)) {
if (chunk.children.length > 1) {
const first = chunk.children[0];
if (first.isTag && first.tag === 'BOOKMARK/') {
const toMove = chunk.children.splice(0, 1);
if (chunk.children.length === 1) {
const child = chunk.children[0];
if (child.isTag && child.tag === 'BOOKMARK/') {
chunk.parent.children.splice(ctx.nodeIdx, 1, child);
return;
}
}
for (let j = 0; j < chunk.children.length - 1; j++) {
const child = chunk.children[j];
if (child.isTag && child.tag === 'BOOKMARK/') {
const toMove = chunk.children.splice(j, 1);
chunk.children.splice(chunk.children.length, 0, ...toMove);
break;
}
}
}
}, {}, async (chunk) => {
if (chunk.isTag && 'PRE' === chunk.tag) {
inPre = false;
}
});

await walkRecursiveAsync(markdownChunks.body, async (chunk, ctx: { nodeIdx: number }) => {
if (chunk.isTag && 'BOOKMARK/' === chunk.tag) {
if (chunk.parent.children.length < 2) {
return;
}
const space: MarkdownTextNode = {
isTag: false,
text: ' ',
comment: 'rewriteHeaders.ts: space before anchor'
};
chunk.parent.children.splice(ctx.nodeIdx, 0, space);
return { nodeIdx: ctx.nodeIdx + 1 };
}
});
}
2 changes: 1 addition & 1 deletion src/odt/postprocess/trimParagraphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function trimParagraphs(markdownChunks: MarkdownNodes) {
while (chunk.children.length > 0) {
const firstChunk = chunk.children[0];
if (firstChunk.isTag === false) {
let origText = firstChunk.text;
const origText = firstChunk.text;
firstChunk.text = firstChunk.text.replace(/^\s+/, '');

if (firstChunk.text === '') {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/idParsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function urlToFolderId(url: string): string | null {

export function getUrlHash(url: string): string {
const idx = url.indexOf('#');
if (idx >= 0) {
if (idx >= 0 && idx < url.length - 1) {
return url.substring(idx).replace('#heading=h.', '#_');
}
return '';
Expand Down
6 changes: 3 additions & 3 deletions test/odt_md/bullets.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
## Bullet List
## Bullet List <a id="_80qew9aprjq8"></a>

* Capability to print standard leave forms from the patient portal
* Pre-loaded standard email templates
* Absence Management encounter
* Quick View Absence Management Worklist
* Leave Types Report

## Ordered List
## Ordered List <a id="_k2lx86ardtkr"></a>

1. Capability to print standard leave forms from the patient portal
2. Pre-loaded standard email templates
3. Absence Management encounter
4. Quick View Absence Management Worklist
5. Leave Types Report

## Mixed Lists
## Mixed Lists <a id="_xnxyy4ptrcvu"></a>

Item before list

Expand Down
18 changes: 10 additions & 8 deletions test/odt_md/confluence.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Confluence to Google Docs Conversion Notes
# Confluence to Google Docs Conversion Notes <a id="_77510dqpcwl"></a>

## Goal
## Goal <a id="_10c0ntqm6mev"></a>

Convert Confluence Documents in to Google Documents for the purpose of using WikiGDrive to publish them.

## Delivery
## Delivery <a id="_i96xic41327t"></a>

A new github repo with a node.js script specific to this conversion.

## High level Process
## High level Process <a id="_wrw8sf3g3pc3"></a>

* Scan all of the documents in a Confluence Space
* Make google documents in a shared drive (two passes will be required so links between documents can be known as content is added).
Expand All @@ -18,7 +18,7 @@ A new github repo with a node.js script specific to this conversion.
* Import content from Confluence Page into Google Documents
* Heading should be headings
* Paragraphs should be paragraphs
* Images (which are attachments in Confluence) should be embedded in google docs
* Images (which are attachments in Confluence) should be embedded in google docs <a id="cukuroni2k4r"></a>
* Macros can be wrapped in {{% curlies %}} and dumped as text
* <strong>Example Block Macro:</strong>
{{% macroname propertyname='value' propertyname='value' %}}
Expand All @@ -30,13 +30,13 @@ A new github repo with a node.js script specific to this conversion.
* Embedded Video should be converted to an image with a hyperlink
* Formatting is not required to be converted.

## Proposed Instructions
## Proposed Instructions <a id="_m98292szff3y"></a>

```
confluence2google <path to space> <path to google shared drive>
```

## Links and Possible Approaches
## Links and Possible Approaches <a id="_sdx7522zhby"></a>

1. Use REST API
1. [Confluence Cloud REST API](https://developer.atlassian.com/cloud/confluence/rest/)
Expand All @@ -50,7 +50,9 @@ confluence2google <path to space> <path to google shared drive>
3. Use HTML
1. [Confluence Export](https://confluence.atlassian.com/confcloud/import-a-confluence-space-724765531.html) that makes an HTML file

## Examples
<a id="ggsym7lvzx37"></a>

## Examples <a id="_rsmqmchgeq17"></a>

Simple - [https://confluence.example.com/display/DOCS/Sample](https://confluence.example.com/display/DOCS/Sample)

Expand Down
36 changes: 18 additions & 18 deletions test/odt_md/example-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
* [Image](#image)
* [Preformatted Text](#preformatted-text)

# Heading 1
# Heading 1 <a id="_pur85qa8iw5l"></a>

## Heading level 2
## Heading level 2 <a id="_rwkjzl1scjzh"></a>

Some normal text with hyperlinks to a [website](https://www.enterprisehealth.com/) and a link to a document on the [shared drive](gdoc:1H6vwfQXIexdg4ldfaoPUjhOZPnSkNn6h29WD6Fi-SBY) with multiple versions of [the link](gdoc:1H6vwfQXIexdg4ldfaoPUjhOZPnSkNn6h29WD6Fi-SBY) because people cut and paste. [Link to test page](gdoc:1iou0QW09pdUhaNtS1RfjJh12lxKAbbq91-SHGihXu_4). Link to [doc in another folder](gdoc:1G4xwfBdH5mvEQyGN16TD2vFUHP8aNgU7wPst-2QTZug).

### Heading level 3 - with a table
### Heading level 3 - with a table <a id="_t3tjnjbci85"></a>

<table>
<tr>
Expand Down Expand Up @@ -43,13 +43,13 @@ After subtable</td>
</tr>
</table>

### Heading 3 - a diagram with links
### Heading 3 - a diagram with links <a id="_ambls07qke35"></a>

[Diagram](gdoc:1Du-DYDST4liLykJl0fHSCvuQYIYhtOfwco-ntn38Dy8)

[Diagram](gdoc:1Du-DYDST4liLykJl0fHSCvuQYIYhtOfwco-ntn38Dy8)

### Heading 3 - with a Table of contents
### Heading 3 - with a Table of contents <a id="_f49uy1gok3t5"></a>

* [Heading 1](#heading-1)
* [Heading level 2](#heading-level-2)
Expand All @@ -60,27 +60,27 @@ After subtable</td>
* [Image](#image)
* [Preformatted Text](#preformatted-text)

# Other examples
# Other examples <a id="_p5x030kzej77"></a>

## Image
## Image <a id="_p56cvcv8bx70"></a>

![](1000000000000640000001CF60FB0243CA95EC14.jpg)

![](10000000000003F0000003F092F85671239C65F9.jpg)

## Preformatted Text
## Preformatted Text <a id="_74or9yzabmh6"></a>

```
This is monospaced text. This should line up |
with this |
```

## Code
## Code <a id="_niow4ogfp967"></a>

Code blocks are part of the Markdown spec, but syntax highlighting isn't. However, many renderers -- like Github's and *Markdown Here* -- support syntax highlighting. Which languages are supported and how those language names should be written will vary from renderer to renderer. *Markdown Here* supports highlighting for dozens of languages (and not-really-languages, like diffs and HTTP headers); to see the complete list, and how to write the language names, see the [highlight.js demo page](http://softwaremaniacs.org/media/soft/highlight/test.html).

### Typescript / Javascript
### Typescript / Javascript <a id="_jt47qp4o5ir1"></a>

{{markdown}}
```javascript
Expand All @@ -102,21 +102,21 @@ myArray.forEach(() => { }); // fat arrow syntax
```
{{/markdown}}

## Video
## Video <a id="_9b72fldy8rju"></a>

From Youtube:

[Google Drive, Docs, and Project Management with GSuite](https://www.youtube.com/watch?v=v6QAIWLCz8I&t=1743s)

## Horizontal Lines
## Horizontal Lines <a id="_q7zgn9e3oi6b"></a>

This is some text separated by a horizontal line

___

This is after the horizontal line.

## Lists
## Lists <a id="_y08cxsphsa2c"></a>

* Bullet 1
* Bullet 2
Expand All @@ -130,13 +130,13 @@ This is after the horizontal line.
2. Alpha 2
3. Alpha 3

## Formatting
## Formatting <a id="_fjarmlobo4r"></a>

Some **bold** **_boldanditalic_*** italic* text

## Equations
## Equations <a id="_guzoh1oxt0s4"></a>

### Using the actual equation object
### Using the actual equation object <a id="_xupy2b5teiu"></a>

```math
E = m c^{2}
Expand All @@ -146,13 +146,13 @@ E = m c^{2}
e^{i \pi} - 1 = 0
```

### Text equivalent
### Text equivalent <a id="_decz1axq5tzn"></a>

*E=mc**2*

Inline $$E = m c^{2}$$ math

## Footnotes
## Footnotes <a id="_44175oezvk2"></a>

1Footnotes should display as a footnote, and should always display at the very end of the document (page)**?** This is some sample text with a footnote.

Expand Down
2 changes: 2 additions & 0 deletions test/odt_md/header-link.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ See [Node setup on the system](#node-setup-on-the-system) for prereq.

[Example Google Drive Shared Folder](gdoc:0AIkOKXbzWCtSUk9PVA)

<a id="n2kl3gvfts47"></a>

# Node setup on the system

## using OS
Expand Down
2 changes: 1 addition & 1 deletion test/odt_md/issue-432.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#### Test Methodology
#### Test Methodology <a id="_pngyfe6dbezk"></a>

MIE will report a count of messages for each supported message type:

Expand Down
2 changes: 1 addition & 1 deletion test/odt_md/issue-435-436.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Editing Existing Questions
## Editing Existing Questions <a id="_dexc5vz6g6ul"></a>

Similar to adding a new question, users must have the proper permission to modify existing questions.

Expand Down
4 changes: 2 additions & 2 deletions test/odt_md/pre-mie.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Request
## Request <a id="_muaembvwg7up"></a>

{{% pre language="html" theme="RDark" %}}
```
Expand All @@ -8,7 +8,7 @@ https://webchartnow.com/fhirr4sandbox/webchart.cgi/fhir/CarePlan/11
```
{{% /pre %}}

## Response
## Response <a id="_5e5g45ahhwrd"></a>

{{% pre language="json" theme="RDark" %}}
```
Expand Down
Loading

0 comments on commit 2e4d1e0

Please sign in to comment.