Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
Signed-off-by: shinichimg <37854342+shinichimg@users.noreply.github.com>
  • Loading branch information
shinichimg committed Jan 30, 2024
1 parent 6758c5b commit d6a5ced
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,31 @@
* Transformed URL (optional).
*/

import {unreachable} from 'devlop'
import {toJsxRuntime} from 'hast-util-to-jsx-runtime'
import {urlAttributes} from 'html-url-attributes'
import { unreachable } from 'devlop'
import { toJsxRuntime } from 'hast-util-to-jsx-runtime'
import { urlAttributes } from 'html-url-attributes'
// @ts-expect-error: untyped.
import {Fragment, jsx, jsxs} from 'react/jsx-runtime'
import { Fragment, jsx, jsxs } from 'react/jsx-runtime'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'
import {visit} from 'unist-util-visit'
import {VFile} from 'vfile'
import { unified } from 'unified'
import { visit } from 'unist-util-visit'
import { VFile } from 'vfile'

const changelog =
'https://github.com/remarkjs/react-markdown/blob/main/changelog.md'

/** @type {PluggableList} */
const emptyPlugins = []
/** @type {Readonly<RemarkRehypeOptions>} */
const emptyRemarkRehypeOptions = {allowDangerousHtml: true}
const emptyRemarkRehypeOptions = { allowDangerousHtml: true }
const safeProtocol = /^(https?|ircs?|mailto|xmpp)$/i

// Mutable because we `delete` any time it’s used and a message is sent.
/** @type {ReadonlyArray<Readonly<Deprecation>>} */
const deprecations = [
{from: 'astPlugins', id: 'remove-buggy-html-in-markdown-parser'},
{from: 'allowDangerousHtml', id: 'remove-buggy-html-in-markdown-parser'},
{ from: 'astPlugins', id: 'remove-buggy-html-in-markdown-parser' },
{ from: 'allowDangerousHtml', id: 'remove-buggy-html-in-markdown-parser' },
{
from: 'allowNode',
id: 'replace-allownode-allowedtypes-and-disallowedtypes',
Expand All @@ -121,20 +121,20 @@ const deprecations = [
id: 'replace-allownode-allowedtypes-and-disallowedtypes',
to: 'disallowedElements'
},
{from: 'escapeHtml', id: 'remove-buggy-html-in-markdown-parser'},
{from: 'includeElementIndex', id: '#remove-includeelementindex'},
{ from: 'escapeHtml', id: 'remove-buggy-html-in-markdown-parser' },
{ from: 'includeElementIndex', id: '#remove-includeelementindex' },
{
from: 'includeNodeIndex',
id: 'change-includenodeindex-to-includeelementindex'
},
{from: 'linkTarget', id: 'remove-linktarget'},
{from: 'plugins', id: 'change-plugins-to-remarkplugins', to: 'remarkPlugins'},
{from: 'rawSourcePos', id: '#remove-rawsourcepos'},
{from: 'renderers', id: 'change-renderers-to-components', to: 'components'},
{from: 'source', id: 'change-source-to-children', to: 'children'},
{from: 'sourcePos', id: '#remove-sourcepos'},
{from: 'transformImageUri', id: '#add-urltransform', to: 'urlTransform'},
{from: 'transformLinkUri', id: '#add-urltransform', to: 'urlTransform'}
{ from: 'linkTarget', id: 'remove-linktarget' },
{ from: 'plugins', id: 'change-plugins-to-remarkplugins', to: 'remarkPlugins' },
{ from: 'rawSourcePos', id: '#remove-rawsourcepos' },
{ from: 'renderers', id: 'change-renderers-to-components', to: 'components' },
{ from: 'source', id: 'change-source-to-children', to: 'children' },
{ from: 'sourcePos', id: '#remove-sourcepos' },
{ from: 'transformImageUri', id: '#add-urltransform', to: 'urlTransform' },
{ from: 'transformLinkUri', id: '#add-urltransform', to: 'urlTransform' }
]

/**
Expand All @@ -155,7 +155,7 @@ export function Markdown(options) {
const rehypePlugins = options.rehypePlugins || emptyPlugins
const remarkPlugins = options.remarkPlugins || emptyPlugins
const remarkRehypeOptions = options.remarkRehypeOptions
? {...options.remarkRehypeOptions, ...emptyRemarkRehypeOptions}
? { ...options.remarkRehypeOptions, ...emptyRemarkRehypeOptions }
: emptyRemarkRehypeOptions
const skipHtml = options.skipHtml
const unwrapDisallowed = options.unwrapDisallowed
Expand All @@ -174,8 +174,8 @@ export function Markdown(options) {
} else {
unreachable(
'Unexpected value `' +
children +
'` for `children` prop, expected `string`'
children +
'` for `children` prop, expected `string`'
)
}

Expand All @@ -186,19 +186,19 @@ export function Markdown(options) {
}

for (const deprecation of deprecations) {
if (Object.prototype.hasOwnProperty(options, deprecation.from)) {
if (options.hasOwnProperty(deprecation.from)) {

Check failure on line 189 in lib/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Do not access Object.prototype method 'hasOwnProperty' from target object.

Check failure on line 189 in lib/index.js

View workflow job for this annotation

GitHub Actions / node

Do not access Object.prototype method 'hasOwnProperty' from target object.
unreachable(
'Unexpected `' +
deprecation.from +
'` prop, ' +
(deprecation.to
? 'use `' + deprecation.to + '` instead'
: 'remove it') +
' (see <' +
changelog +
'#' +
deprecation.id +
'> for more info)'
deprecation.from +
'` prop, ' +
(deprecation.to
? 'use `' + deprecation.to + '` instead'
: 'remove it') +
' (see <' +
changelog +
'#' +
deprecation.id +
'> for more info)'
)
}
}
Expand All @@ -212,7 +212,7 @@ export function Markdown(options) {
hastTree = {
type: 'element',
tagName: 'div',
properties: {className},
properties: { className },
// Assume no doctypes.
children: /** @type {Array<ElementContent>} */ (
hastTree.type === 'root' ? hastTree.children : [hastTree]
Expand All @@ -238,7 +238,7 @@ export function Markdown(options) {
if (skipHtml) {
parent.children.splice(index, 1)
} else {
parent.children[index] = {type: 'text', value: node.value}
parent.children[index] = { type: 'text', value: node.value }
}

return index
Expand All @@ -250,7 +250,7 @@ export function Markdown(options) {

for (key in urlAttributes) {
if (
urlAttributes.hasOwnProperty( key) &&
urlAttributes.hasOwnProperty(key) &&

Check failure on line 253 in lib/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Do not access Object.prototype method 'hasOwnProperty' from target object.

Check failure on line 253 in lib/index.js

View workflow job for this annotation

GitHub Actions / node

Do not access Object.prototype method 'hasOwnProperty' from target object.
node.properties.hasOwnProperty(key)

Check failure on line 254 in lib/index.js

View workflow job for this annotation

GitHub Actions / lts/gallium

Do not access Object.prototype method 'hasOwnProperty' from target object.

Check failure on line 254 in lib/index.js

View workflow job for this annotation

GitHub Actions / node

Do not access Object.prototype method 'hasOwnProperty' from target object.
) {
const value = node.properties[key]
Expand All @@ -266,8 +266,8 @@ export function Markdown(options) {
let remove = allowedElements
? !allowedElements.includes(node.tagName)
: disallowedElements
? disallowedElements.includes(node.tagName)
: false
? disallowedElements.includes(node.tagName)
: false

if (!remove && allowElement && typeof index === 'number') {
remove = !allowElement(node, index, parent)
Expand Down

0 comments on commit d6a5ced

Please sign in to comment.