diff --git a/packages/bygger/src/translations/utils.test.ts b/packages/bygger/src/translations/utils.test.ts
index 2584598c0..fe8c48f85 100644
--- a/packages/bygger/src/translations/utils.test.ts
+++ b/packages/bygger/src/translations/utils.test.ts
@@ -501,23 +501,21 @@ describe('Skjema med globale oversettelser som inneholder linjeskift', () => {
},
},
};
+
it('fjerner linjeskift i tekster som skal eksporteres', () => {
const eksport = getTextsAndTranslationsForForm(form, translations);
- expect(eksport).toHaveLength(6);
+ expect(eksport).toHaveLength(2);
expect(eksport[0].text).toBe('Veiledning');
expect(eksport[0].en).toBe('Guidance (Global Tekst)');
expect(eksport[0]['nn-NO']).toBe('Rettleiing (Global Tekst)');
- expect([eksport[1].text, eksport[2].text, eksport[3].text]).toEqual(['NAV sender svar. ', '
', ' Se ']);
- expect([eksport[1].en, eksport[2].en, eksport[3].en]).toEqual(['NAV sends answers. ', '
', ' See ']);
- expect([eksport[1]['nn-NO'], eksport[2]['nn-NO'], eksport[3]['nn-NO']]).toEqual([
- 'NAV sender svar. ',
- '
',
- ' Sjå ',
- ]);
+ expect(eksport[1].text).toEqual('NAV sender svar.
Se [link](https://www.nav.no/person/).');
+ expect(eksport[1].en).toEqual('NAV sends answers.
See [link](https://www.nav.no/person/).');
+ expect(eksport[1]['nn-NO']).toEqual('NAV sender svar.
Sjå [lenke](https://www.nav.no/person/).');
});
});
+
describe('testGetCSVfileHeaders', () => {
it('Test headers with only origin form text', () => {
const actual = getTextsAndTranslationsHeaders([] as FormioTranslationMap);
diff --git a/packages/shared-components/src/util/html/StructuredHtml/StructuredHtmlElement.test.ts b/packages/shared-components/src/util/html/StructuredHtml/StructuredHtmlElement.test.ts
index 0d0e74d72..33379b0f6 100644
--- a/packages/shared-components/src/util/html/StructuredHtml/StructuredHtmlElement.test.ts
+++ b/packages/shared-components/src/util/html/StructuredHtml/StructuredHtmlElement.test.ts
@@ -171,15 +171,17 @@ describe('StructuredHtmlElement', () => {
const withLinkJsonMarkdownChildren = (
(withLinkJson.children[0] as HtmlAsJsonElement).children[0] as HtmlAsJsonElement
).children;
- expect((withLinkJsonMarkdownChildren[0] as HtmlAsJsonTextElement).textContent).toBe('Punkt 1 med ');
- expect((withLinkJsonMarkdownChildren[1] as HtmlAsJsonTextElement).textContent).toBe('[lenketekst](www.url.no)');
+ expect((withLinkJsonMarkdownChildren[0] as HtmlAsJsonTextElement).textContent).toBe(
+ 'Punkt 1 med [lenketekst](www.url.no)',
+ );
});
it('converts strong to json with markdown', () => {
const withStrongJson = withStrong.toJson(true);
const withStrongJsonMarkdownChildren = (withStrongJson.children[0] as HtmlAsJsonElement).children;
- expect((withStrongJsonMarkdownChildren[0] as HtmlAsJsonTextElement).textContent).toBe('Avsnitt med ');
- expect((withStrongJsonMarkdownChildren[1] as HtmlAsJsonTextElement).textContent).toBe('**fet skrift**');
+ expect((withStrongJsonMarkdownChildren[0] as HtmlAsJsonTextElement).textContent).toBe(
+ 'Avsnitt med **fet skrift**.',
+ );
});
it('does not convert strong to markdown when conversion was done without skipping within given tags', () => {
diff --git a/packages/shared-components/src/util/html/StructuredHtml/StructuredHtmlElement.ts b/packages/shared-components/src/util/html/StructuredHtml/StructuredHtmlElement.ts
index 078b7e848..da4c42c47 100644
--- a/packages/shared-components/src/util/html/StructuredHtml/StructuredHtmlElement.ts
+++ b/packages/shared-components/src/util/html/StructuredHtml/StructuredHtmlElement.ts
@@ -160,14 +160,15 @@ class StructuredHtmlElement extends StructuredHtml {
}
toJson(getMarkdown?: boolean): HtmlAsJsonElement {
+ const markdown = getMarkdown && this.containsMarkdown ? this.markdown : undefined;
+ const children = markdown ? [new StructuredHtmlText(markdown, { isMarkdownText: true })] : this.children;
+
return {
id: this.id,
type: 'Element',
tagName: this.tagName,
attributes: this.attributes,
- children: (getMarkdown && this.containsMarkdown ? this.childrenAsMarkdown ?? [] : this.children).map((child) =>
- child.toJson(getMarkdown),
- ),
+ children: children.map((child: StructuredHtml) => child.toJson(getMarkdown)),
};
}