Code Monkey home page Code Monkey logo

Comments (3)

anvu69 avatar anvu69 commented on July 30, 2024

Same issue!
My BBCode: [url]http://dantri.com.vn/.../20180724072628474.htm[/url]
And i receive tag: <a >http://dantri.com.vn/.../20180724072628474.htm</a> without href attrs.

But BBCode has type [url=http://dantri.com.vn/..../20180724072628474.htm]content....[/url], it return <a href="http://dantri.com.vn/..../20180724072628474.htm">content....</a> with href attrs!

Here is my code:

import bbob from '@bbob/core'
import { createPreset } from '@bbob/preset'
import { render } from '@bbob/html'
import _ from 'lodash'

const reduceAttr = (attrs) => {
  return _.reduce(
    attrs,
    (result, value, key) => {
      (result['attr'] || (result['attr'] = [])).push(value)
      return result.attr
    },
    {}
  )
}

const preset = createPreset({
  url: (node, { render }) => {
    return {
        tag: 'a',
        attrs: {
          href: reduceAttr(node.attrs) !== {}
            ? reduceAttr(node.attrs)[0]
            : render(node.content),
        },
        content: node.content
      }
  }
})

export default {
  convertBBCode (content) {
    if (content) {
      const result = bbob(preset()).process(content, { render }).html.replace(/(?:\r\n|\r|\n)/g, '<br>')
      return result
    } else {
      return ''
    }
  }
}

Update CodeSandbox link
Edit BBOB Bug

from bbob.

JiLiZART avatar JiLiZART commented on July 30, 2024

Thanks for reporting! I take a look on this problem soon.
PS: You can use

import BBCode from '@bbob/react/es/Component'

instead of using html-react-parser

from bbob.

ironsm4sh avatar ironsm4sh commented on July 30, 2024

I have a similar problem.
From the readme at bbob-parser. trying the example will parse into
image
instead of

[
    {
        "tag": "url",
        "attrs": {
            "url": "https://github.com"
        },
        "content": ["hello", " ", "world!"]
    }
]

The URL attribute is nowhere to be found, and a new attribute with the name of the url has appeared.

As a temporary fix, reverting back to version 1.3.2 works (but this breaks other things, such as the ability to use the enableEscapeTags option)

from bbob.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.