We are creating a react module to parse a Markdown formatted text into PDF using the react-pdf library.
Using the component is quite simple. Just insert the <Markdown />
JSX tag as a component in the React-PDF Page
:
<PDFViewer width={500} height={800}>
<Document>
<Page size="A4" style={styles.page}>
<Markdown md={markdownText} />
</Page>
</Document>
</PDFViewer>
The library converts the Markdown string by composing the AST and then traverse the resultant tree in a recursive fashion.
- To parse the Markdown document to Abstract Syntax Tree we are using Remark.js
To test the development of the library:
-
Build the library on watch mode
# In the root folder npm run build -- --watch
That will keep the builder running and watching for any change.
-
Run the test server
# In the server-test folder # First install dependencies npm ci # Second run the server in dev mode num run dev
The server has the dependency to the lib as a folder link, which means that it will get any modification without the need to restart the server. Nonetheless, any changes to the library will require to refresh the page.
This project includes code from react-pdf library in the form of a dependency, which is licensed under the MIT License. The MIT License from this library can be found in the LICENSE.MIT
file and in the original project.
The extensions and additional code in this project are licensed under the Apache License 2.0. The full text of the Apache License can be found in the LICENSE
file.