code-preview-component
TypeScript icon, indicating that this package has built-in type declarations

0.3.5 • Public • Published

code-preview-component

React component for displaying code with examples in multiple languages.

Demo of the WIP-State can be seen here: External Test - Gitlab Pages, Internal Demo - Gitlab Pages.

To Dos

v1.0

  • Switch Language
  • Highlight Code
    • Props: Enable/Disable Line Numbers
    • Props: Change Style
  • Compile UML to graphic

Ideas

  • Side-by-side viewing code. As example:
    • HTML, JS and CSS to get the whole picture
    • Compare alike snippets
  • Show Result of code - Dartpad, Codepen integration

Example

Currently it's possible to add a Language and a Code Snippet.

import CodePreview from "code-preview-component";
 
const langMap = new Map<Langsstring>();
// Init the Langauges
langMap.set(Langs.JavaScript, `console.log("Hello world!")`);
 
return (
  <CodePreview languageEntries={this.state.languageEntries} />
);

Note

The react-syntax-highlighter is lazy loaded through React.lazy for faster feedback. For this the async implementation of the highlighter is used. This also splits the highlighter-dependency into chunks while building, which are dynamically loaded, depending on language currently displayed. There are also custom type-definitions provided for react-syntax-highlighter, as the ones on @types/react-syntax-highlighter don't yet include the async lazy loading version.

@material-ui/core and @material-ui/icons is just used as webpack.external, so the using module can handle code splitting.

Icon - Sources

In General icons are taken from DevIcon.

  • Rustlang Logo: Rustlang Icon Logo
  • For this logo the size and viewbox has been adjustet, as the original contains large borders: Bash Logo

Package Sidebar

Install

npm i code-preview-component

Weekly Downloads

1

Version

0.3.5

License

MIT

Unpacked Size

4.44 MB

Total Files

34

Last publish

Collaborators

  • moblaa