Skip to content
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

Feature/#126 download md #130

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/react-app/src/common-app/helpers/download-md-section.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const download = (blob: Blob, filename: string) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should move to common (can be reused by other application), and must be renamed to download-file-helper

we will apply this on develop

const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
document.body.appendChild(a);
a.style.display = 'none';
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
a.remove();
};
1 change: 1 addition & 0 deletions apps/react-app/src/common-app/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './download-md-section';
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import { exportManfredJSonToWordAndDownload, parseStringToManfredJSon } from '@lemoncode/manfred2word';
import { exportManfredJSonToMarkdown } from '@lemoncode/manfred2md';
import { DEFAULT_EXPORT_FILENAME } from '@/core';
import { download } from '@/common-app/helpers';
import { TemplateExport } from './template-export.component';
import { exportManfredJSonToMarkdown } from '@lemoncode/manfred2md';

export const TemplateExportContainer: React.FC = () => {
const parseManfredJson = (text: string) => {
Expand All @@ -12,20 +13,25 @@ export const TemplateExportContainer: React.FC = () => {

const onExportJsonToWord = async (text: string) => {
try {
const manfredJsonContent = parseManfredJson(text);

const manfredJsonContent = parseStringToManfredJSon(text);
await exportManfredJSonToWordAndDownload(DEFAULT_EXPORT_FILENAME, manfredJsonContent);
} catch (error) {
alert('Hay un error, no está utilizando el formato correcto');
console.error(error);
}
};

const onExportJsonToMarkdown = (text: string) => {
const manfredJsonContent = parseManfredJson(text);
const onExportJsonToMarkdown = async (text: string) => {
try {
const manfredJsonContent = parseManfredJson(text);
const content = exportManfredJSonToMarkdown(manfredJsonContent);
const blob = new Blob([content], { type: 'text/markdown' });

// TODO Flavio: Integrate Download
console.log(exportManfredJSonToMarkdown(manfredJsonContent));
await download(blob, 'manfred.md');
} catch (error) {
console.error(error);
alert('Hay un error, no está utilizando el formato correcto');
}
};

return <TemplateExport onExportToWord={onExportJsonToWord} onExportToMarkdown={onExportJsonToMarkdown} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const textarea = css`
color: ${theme.palette.light[700]};
`;

export const buttonContainer = css `
export const buttonContainer = css`
display: flex;
flex-direction: row;
justify-content: center;
Expand All @@ -70,4 +70,3 @@ export const buttonClass = css`
width: 100%;
}
`;

3 changes: 1 addition & 2 deletions packages/manfred2md/src/common/string-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export const removeIndent = (str: string) => str.replace(/^\s+/gm, "");

export const removeIndent = (str: string) => str.replace(/^\s+/gm, '');
1 change: 0 additions & 1 deletion packages/manfred2md/src/engine/json-parse.business.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// TOD: move this to common library
// TODO: Fix this right now is removing \n of the inner string fields
export const removeInvalidChars = (json: string): string => {
Expand Down
2 changes: 0 additions & 2 deletions packages/manfred2md/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * from './engine';


Loading