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

[#162048444] Markdownviewer component #808

Merged
merged 17 commits into from
Jan 21, 2019
Merged

Conversation

fpersico
Copy link
Contributor

No description provided.

@digitalcitizenship
Copy link

digitalcitizenship commented Jan 21, 2019

Warnings
⚠️

Please include a description of your PR changes.

Affected stories

  • 🌟 #162048444: Il componente Markdown va rivisto/riscritto

New dependencies added: buffer, path-browserify, react-native-webview, remark, remark-custom-blocks, remark-html and rn-nodeify.

buffer

Author: Feross Aboukhadijeh

Description: Node.js Buffer API, for the browser

Homepage: https://github.com/feross/buffer

Createdalmost 5 years ago
Last Updated5 days ago
LicenseMIT
Maintainers1
Releases79
Direct Dependenciesbase64-js and ieee754
Keywordsarraybuffer, browser, browserify, buffer, compatible, dataview and uint8array
This README is too long to show.

path-browserify

Author: James Halliday

Description: the path module from node core for browsers

Homepage: https://github.com/substack/path-browserify

Createdabout 5 years ago
Last Updated16 days ago
LicenseMIT
Maintainers38
Releases3
Direct Dependencies
Keywordspath, browser and browserify
README

path-browserify

the path module from node core for browsers

react-native-webview

Author: Jamon Holmgren

Description: React Native WebView component for iOS, Android, and Windows 10 (coming soon)

Homepage: https://github.com/react-native-community/react-native-webview#readme

Createdabout 3 years ago
Last Updated3 days ago
LicenseMIT
Maintainers4
Releases44
Direct Dependenciesescape-string-regexp and fbjs
README

React Native WebView - a Modern, Cross-Platform WebView for React Native

React Native WebView is a modern, well-supported, and cross-platform WebView for React Native. It is intended to be a replacement for the built-in WebView (which will be removed from core).

We just swapped out the React Native WebView in our app with the version from React Native Community. The swap took less than a day, required almost no code modifications, and is faster and CSS works better. Props to everyone in the community (including those at Infinite Red) that helped get that component split out.

Garrett McCullough, mobile engineer at Virta Health

Platforms Supported

  • iOS (both UIWebView and WKWebView)
  • Android
  • Windows 10 (coming soon)

Note: React Native WebView is not currently supported by Expo unless you "eject".

Versioning

If you need the exact same WebView as the one from react-native, please use version 2.0.0. Future versions will follow semantic versioning.

Getting Started

$ yarn add react-native-webview
$ react-native link react-native-webview

Read our Getting Started Guide for more.

Usage

Import the WebView component from react-native-webview and use it like so:

import React, { Component } from "react";
import { StyleSheet, Text, View } from "react-native";
import { WebView } from "react-native-webview";

// ...
class MyWebComponent extends Component {
  render() {
    return (
      <WebView
        source={{ uri: "https://infinite.red/react-native" }}
        style={{ marginTop: 20 }}
        onLoadProgress={e => console.log(e.nativeEvent.progress)}
      />
    );
  }
}

For more, read the API Reference and Guide. If you're interested in contributing, check out the Contributing Guide.

Migrate from React Native core WebView to React Native WebView

Simply install React Native WebView and then use it in place of the core WebView. Their APIs are currently identical, except that this package defaults useWebKit={true} unlike the built-in WebView.

Troubleshooting

  • If you're getting Invariant Violation: Native component for "RNCWKWebView does not exist" it likely means you forgot to run react-native link or there was some error with the linking process

Contributor Notes

  • I've removed all PropTypes for now. Instead, we'll be using Flow types. TypeScript types will be added at a later date.
  • UIWebView is not tested fully and you will encounter some yellow warning boxes. Since it is deprecated, we don't intend to put a lot of time into supporting it, but feel free to submit PRs if you have a special use case. Note that you will need to specify useWebKit={false} to use UIWebView
  • After pulling this repo and installing all dependencies, you can run flow on iOS and Android-specific files using the commands:
    • yarn test:ios:flow for iOS
    • yarn test:android:flow for Android
  • If you want to add another React Native platform to this repository, you will need to create another .flowconfig for it. If your platform is example, copy the main flowconfig and rename it to .flowconfig.example. Then edit the config to ignore other platforms, and add .*/*[.]example.js to the ignore lists of the other platforms. Then add an entry to package.json like this:
    • "test:example:flow": "flow check --flowconfig-name .flowconfig.example"
  • Currently you need to install React Native 0.57 to be able to test these types - flow check will not pass against 0.56.

Maintainers

License

MIT

remark

Author: Titus Wormer

Description: Markdown processor powered by plugins

Homepage: https://remark.js.org

Createdabout 5 years ago
Last Updated16 days ago
LicenseMIT
Maintainers5
Releases35
Direct Dependenciesremark-parse, remark-stringify and unified
Keywordsmarkdown, abstract, syntax, tree, ast, parse, stringify and process
README

remark Travis Coverage Downloads Size Chat

remark is a markdown processor powered by plugins part of the
unified collective.

Don’t need the parser? Or the compiler? That’s OK.


Announcing the unified collective! 🎉
Read more about it on Medium »

Sponsors



🥇 ZEIT


🥇 Gatsby


🥉 Compositor


Holloway




You?

Installation

npm:

npm install remark

Usage

Common example

This example lints markdown and turns it into HTML.

var remark = require('remark')
var recommended = require('remark-preset-lint-recommended')
var html = require('remark-html')
var report = require('vfile-reporter')

remark()
  .use(recommended)
  .use(html)
  .process('## Hello world!', function(err, file) {
    console.error(report(err || file))
    console.log(String(file))
  })

Yields:

1:1  warning  Missing newline character at end of file  final-newline  remark-lint

⚠ 1 warning
<h2>Hello world!</h2>
Settings through data

This example prettifies markdown and configures remark-parse and
remark-stringify through data.

var remark = require('remark')

remark()
  .data('settings', {commonmark: true, emphasis: '*', strong: '*'})
  .process('_Emphasis_ and __importance__', function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

Yields:

*Emphasis* and **importance**
Settings through a preset

This example prettifies markdown and configures remark-parse and
remark-stringify through a preset.

var remark = require('remark')

remark()
  .use({
    settings: {commonmark: true, emphasis: '*', strong: '*'}
  })
  .process('_Emphasis_ and __importance__', function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

Yields:

*Emphasis* and **importance**

License

MIT © Titus Wormer

remark-custom-blocks

Author: Victor Felder

Description: This plugin parses custom Markdown syntax to create new custom blocks. It adds new nodes types to the [mdast][mdast] produced by [remark][remark]:

Homepage: http:https://npmjs.com/package/remark-custom-blocks

Createdover 1 year ago
Last Updated16 days ago
LicenseMIT
Maintainers2
Releases34
Direct Dependenciesspace-separated-tokens
Keywordsremark
README

remark-custom-blocks Build Status Coverage Status

This plugin parses custom Markdown syntax to create new custom blocks.
It adds new nodes types to the mdast produced by remark:

  • {yourType}CustomBlock

If you are using rehype, the stringified HTML result will be divs with configurable CSS classes.

It is up to you to have CSS rules producing the desired result for these classes.

The goal is to let you create blocks or panels somewhat similar to these.

Each custom block can specify CSS classes and whether users are allowed or required to add a custom title to the block.

Only inline Markdown will be parsed in titles.

Installation

npm:

npm install remark-custom-blocks

Usage, Configuration, Syntax

Configuration:

The configuration object follows this pattern:

trigger: {
  classes: String, space-separated classes, optional, default: ''
  title: String, 'optional' | 'required', optional, default: custom titles not allowed
}

Dependencies:

const unified = require('unified')
const remarkParse = require('remark-parse')
const stringify = require('rehype-stringify')
const remark2rehype = require('remark-rehype')

const remarkCustomBlocks = require('remark-custom-blocks')

Usage:

unified()
  .use(remarkParse)
  .use(remarkCustomBlocks, {
    foo: {
      classes: 'a-class another-class'
    },
    bar: {
      classes: 'something',
      title: 'optional'
    },
    qux: {
      classes: 'qux-block',
      title: 'required'
    },
    spoiler: {
      classes: 'spoiler-block',
      title: 'optional',
      details: true
    },
  })
  .use(remark2rehype)
  .use(stringify)

The sample configuration provided above would have the following effect:

  1. Allows you to use the following Markdown syntax to create blocks:

    [[foo]]
    | content
    
    [[bar]]
    | content
    
    [[bar | my **title**]]
    | content
    
    [[qux | my title]]
    | content
    
    [[spoiler | my title]]
    | content
    • Block foo cannot have a title, [[foo | title]] will not result in a block.
    • Block bar can have a title but does not need to.
    • Block qux requires a title, [[qux]] will not result in a block.
  2. This Remark plugin would create mdast nodes for these two blocks, these nodes would be of type:

    • fooCustomBlock, content will be in fooCustomBlockBlody
    • barCustomBlock, content in barCustomBlockBody, optional title in barCustomBlockHeading
    • quxCustomBlock, content in quxCustomBlockBody, required title in quxCustomBlockHeading
  3. If you're using rehype, you will end up with these 4 divs and 1 details:

    <div class="custom-block a-class another-class">
      <div class="custom-block-body"><p>content</p></div>
    </div>
    
    <div class="custom-block something">
      <div class="custom-block-body"><p>content</p></div>
    </div>
    
    <div class="custom-block something">
      <div class="custom-block-heading">my <strong>title</strong></div>
      <div class="custom-block-body"><p>content</p></div>
    </div>
    
    <div class="custom-block qux-block">
      <div class="custom-block-heading">my title</div>
      <div class="custom-block-body"><p>content</p></div>
    </div>
    
     <details class="custom-block spoiler-block">
      <summary class="custom-block-heading">my title</summary>
      <div class="custom-block-body"><p>content</p></div>
    </details>

License

MIT © Zeste de Savoir

remark-html

Author: Titus Wormer

Description: Compile Markdown to HTML with remark

Homepage: https://github.com/remarkjs/remark-html#readme

Createdabout 3 years ago
Last Updated16 days ago
LicenseMIT
Maintainers5
Releases16
Direct Dependencieshast-util-sanitize, hast-util-to-html, mdast-util-to-hast and xtend
Keywordsmarkdown, html, stringify, compile and remark
README

remark-html

Build
Coverage
Downloads
Chat
Sponsors
Backers

Compile markdown to HTML with remark.

⚠️ This package essentially packs remark-rehype and
rehype-stringify, and although it does support some
customisation, it isn’t very pluggable. It’s probably smarter to use
remark-rehype directly and benefit from the rehype
ecosystem.

Installation

npm:

npm install remark-html

Usage

Say we have the following file, example.md:

# Hello & World

> A block quote.

* Some _emphasis_, **importance**, and `code`.

And our script, example.js, looks as follows:

var fs = require('fs')
var unified = require('unified')
var markdown = require('remark-parse')
var html = require('remark-html')

unified()
  .use(markdown)
  .use(html)
  .process(fs.readFileSync('example.md'), function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

Now, running node example yields:

<h1>Hello &#x26; World</h1>
<blockquote>
<p>A block quote.</p>
</blockquote>
<ul>
<li>Some <em>emphasis</em>, <strong>importance</strong>, and <code>code</code>.</li>
</ul>

API

remark.use(html[, options])

options

All options except for sanitize are passed to
hast-util-to-html.

options.sanitize

How to sanitise the output (Object or boolean, default: false).

If false, no HTML is sanitized, and dangerous HTML is left unescaped.

If true or an object, sanitation is done by hast-util-sanitize
If an object is passed in, it’s given as a schema to hast-util-sanitize.
If true, input is sanitised according to GitHub’s sanitation rules.

Note that raw HTML in markdown cannot be sanitized, so it’s removed.
A schema can still be used to allow certain values from integrations
though.
To support HTML in markdown, use rehype-raw.

For example, to add strict sanitation but allowing classNames, use
something like:

// ...
var merge = require('deepmerge')
var github = require('hast-util-sanitize/lib/github')

var schema = merge(github, {attributes: {'*': ['className']}})

remark()
  .use(html, {sanitize: schema})
  .processSync(/* ... */)

CommonMark

You still need to set commonmark: true in
remark-parses options.

CommonMark support is a goal but not (yet) a necessity. There are
some (roughly 115 of 550, relating to inline precedence, lists, emphasis
and importance) issues which I’d like to cover in the future. Note that
this sounds like a lot, but they have to do with obscure differences
which do not often occur in the real world.

Integrations

remark-html works great with:

All MDAST nodes can be compiled to HTML. Unknown MDAST
nodes are compiled to div nodes if they have children or text nodes
if they have value.

In addition, remark-html can be told how to compile nodes through
three data properties (more information):

  • hName — Tag-name to compile as
  • hChildren — HTML content to add (instead of children and value),
    in HAST
  • hProperties — Map of attributes to add

For example, the following node:

{
  type: 'emphasis',
  data: {
    hName: 'i',
    hProperties: {className: 'foo'},
    hChildren: [{type: 'text', value: 'bar'}]
  },
  children: [{type: 'text', value: 'baz',}]
}

...would yield:

<i class="foo">bar</i>

Contribute

See contributing.md in remarkjs/remark for ways to get
started.

This organisation has a Code of Conduct. By interacting with this
repository, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer

rn-nodeify

Author: Unknown

Description: Run after npm install and you can use node core modules and npm modules that use them in your React Native app.

Homepage: https://github.com/mvayngrib/rn-nodeify#readme

Createdover 3 years ago
Last Updated16 days ago
LicenseMIT
Maintainers3
Releases46
Direct Dependencies@yarnpkg/lockfile, deep-equal, findit, fs-extra, minimist, object.pick, run-parallel, semver and xtend
README

rn-nodeify

Run after npm install and you can use node core modules and npm modules that use them in your React Native app.

What is solves

If your project has no non-React-Native dependencies, you don't need this module, and you should just check out './shims.js' for the core node modules to use individually.

However, with bigger projects that don't reimplement every wheel from scratch, somewhere in your dependency tree, something uses a core node module. I found myself building this because in my React Native app, I wanted to use bitcoinjs-lib, levelup, bittorrent-dht, and lots of fun crypto. If that sounds like you, keep reading.

What it does

rn-nodeify --install
installs shims for core node modules, see './shims.js' for the current mappings. It recurses down node_modules and modifies all the package.json's in there to add/update the browser and react-native fields. It sounds scary because it is. However, it does work.

rn-nodeify --hack
Now that you're scared, I should also mention that there are some package-specific hacks (see './pkg-hacks.js'), for when the React Native packager choked on something that Webpack and Browserify swallowed.

If you're looking for a saner approach, check out ReactNativify. I haven't tested it myself, but I think philikon will be happy to help.

Usage

rn-nodeify <options>

Options

--install     install node core shims (default: install all), fix the "browser"
              and "react-native" fields in the package.json's of dependencies
--hack        hack individual packages that are known to make the React Native packager choke

Examples

# install all shims and run package-specific hacks
rn-nodeify --install --hack
# install specific shims
rn-nodeify --install "fs,dgram,process,path,console"
# install specific shims and hack
rn-nodeify --install "fs,dgram,process,path,console" --hack

It is recommended to add this command to the "postinstall" script in your project's package.json

"scripts": {
  "start": "node node_modules/react-native/local-cli/cli.js start",
  "postinstall": "rn-nodeify --install fs,dgram,process,path,console --hack"
}

rn-nodeify will create a shim.js file in your project root directory. The first line in index.ios.js / index.android.js should be to import it (NOT require it!)

import './shim'

If you are using the crypto shim, you will need to manually uncomment the line to require('crypto') in shim.js, this is because as of react-native 0.49, dynamically requiring a library is no longer allowed.

Some shims may require linking libraries, be sure to run react-native link after installing new shims if you run into problems.

Example Apps / Workflows

Example Workflow

copied from react-native-crypto

  1. Install and shim
npm i --save react-native-crypto
# install peer deps
npm i --save react-native-randombytes
react-native link react-native-randombytes
# install latest rn-nodeify
npm i --save-dev mvayngrib/rn-nodeify
# install node core shims and recursively hack package.json files
# in ./node_modules to add/update the "browser"/"react-native" field with relevant mappings
./node_modules/.bin/rn-nodeify --hack --install
  1. rn-nodeify will create a shim.js in the project root directory
// index.ios.js or index.android.js
// make sure you use `import` and not `require`!
import './shim.js'
// ...the rest of your code
import crypto from 'crypto'
// use crypto
console.log(crypto.randomBytes(32).toString('hex'))

Please note...

Generated by 🚫 dangerJS

@fpersico fpersico changed the title Markdownviewer component [#162048444] Markdownviewer component Jan 21, 2019
@codecov
Copy link

codecov bot commented Jan 21, 2019

Codecov Report

Merging #808 into master will decrease coverage by 0.27%.
The diff coverage is 37.17%.

@@            Coverage Diff             @@
##           master     #808      +/-   ##
==========================================
- Coverage    49.7%   49.42%   -0.28%     
==========================================
  Files         189      194       +5     
  Lines        3595     3672      +77     
  Branches      664      672       +8     
==========================================
+ Hits         1787     1815      +28     
- Misses       1805     1854      +49     
  Partials        3        3

shim.js Outdated
@@ -0,0 +1,26 @@
if (typeof __dirname === 'undefined') global.__dirname = '/'
Copy link
Contributor

Choose a reason for hiding this comment

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

is this file autogenerated? can we add either a comment here (or in the README) explaining what it is, where does it comes from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes file is autogenerated by rn-nodeify. There is already a comment on import of the file https://github.com/teamdigitale/italia-app/pull/808/files#diff-168726dbe96b3ce427e7fedce31bb0bcR4.

Copy link
Contributor

Choose a reason for hiding this comment

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

then it shouldn't be committed

];

function getInternalRoute(href: string): Option<string> {
const parsed = href.split(INTERNAL_TARGET_PREFIX);
Copy link
Contributor

Choose a reason for hiding this comment

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

return Option(href.split(INTERNAL_TARGET_PREFIX))
  .filter(_ => _.length === 2 && _[0] === "")
  .chain(_ => fromNullable(ALLOWED_ROUTE_NAMES.find(_.toUpperCase()));

}

export function handleInternalLink(dispatch: Dispatch, href: string) {
const maybeInternalRoute = getInternalRoute(href);
Copy link
Contributor

Choose a reason for hiding this comment

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

getInternalRoute(href).map(routeName => dispatch(
      NavigationActions.navigate({
        routeName
      })
    )));

@@ -0,0 +1,184 @@
import React from "react";
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment that explain the purpose of this

}
};

const COMPILE_ERROR_HTML = `<p>${I18n.t("global.markdown.decodeError")}<p>`;
Copy link
Contributor

Choose a reason for hiding this comment

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

avoid the dependency to I18n, instead of rendering a decoding error, provide an optional onError callback to the component

htmlBodyClasses?: string
) => {
InteractionManager.runAfterInteractions(() => {
remark()
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems that

remark()
        .use(remarkCustomBlocks, REMARK_CUSTOM_BLOCKS_CONFIG)
        .use(remarkHtml)

can be executed once and the result used across instances on the component?

@@ -0,0 +1,51 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

this file should probably to be a .ts, not a .tsx

@@ -0,0 +1,24 @@
/**
* Types used by the MarkdownViewer component.
Copy link
Contributor

Choose a reason for hiding this comment

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

Types of messages sent from inside the webview.

@@ -2,16 +2,15 @@ import * as pot from "italia-ts-commons/lib/pot";
import { H1, View } from "native-base";
import * as React from "react";
import { StyleSheet, TouchableOpacity } from "react-native";
import { Col, Grid } from "react-native-easy-grid";
Copy link
Contributor

Choose a reason for hiding this comment

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

can't use Grid anymore now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted. Was not working but now with the webview "autoheight" function it works as expected.

</View>
<MarkdownViewer
markdown={message.content.markdown}
htmlBodyClasses={"message--detail"}
Copy link
Contributor

Choose a reason for hiding this comment

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

could you document the usage of this parameter? I don't see message--detail defined anywhere

@cloudify cloudify merged commit e99fb74 into master Jan 21, 2019
@cloudify cloudify deleted the markdownviewer-component branch January 21, 2019 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants