jarrett / rbbcode Goto Github PK
View Code? Open in Web Editor NEWConverts BBCode to HTML. Gracefully handles invalid input. Built on Treetop.
Converts BBCode to HTML. Gracefully handles invalid input. Built on Treetop.
$ sudo gem tumble This command is deprecated, Gemcutter.org is the primary source for gems.
$ sudo gem install --no-ri --no-rdoc rbbcode Successfully installed rbbcode-0.1.3 1 gem installed
$ irb irb(main):001:0> require 'rubygems' => false irb(main):002:0> require 'rbbcode' LoadError: no such file to load -- rbbcode
$ ls /var/lib/gems/1.8/gems/rbbcode-0.1.3/ README spec
This one has me scratching my head.
I added a complex_blockquote to rbbcode (https://github.com/PeteMichaud/rbbcode/tree/pete), and discovered that nesting them gave me this error:
RbbCode.new.convert("[quote=Pete Michaud]\n[quote=Author]This is a quote[/quote]\n\n[quote=Another Author]This is a [b]quote[/b][/quote]\n[/quote]")
#=> NameError: undefined local variable or method `elements' for nil:NilClass
So I tracked that error down to https://github.com/PeteMichaud/rbbcode/blob/pete/lib/rbbcode/node_extensions.rb#L32 where elements is called.
I'm really confused because apparently self.elements is failing because self is nil.
I thought maybe it was my fault and there was something wrong with the grammar for complex_quote, so I poked around and discovered that nesting any kind quote hase the same result:
RbbCode.new.convert("[quote][quote]This is a quote[/quote][/quote]")
#=> NameError: undefined local variable or method `elements' for nil:NilClass
These both work fine:
RbbCode.new.convert("[b][i]Text[/i][/b]")
RbbCode.new.convert("[i][i]Text[/i][/i]")
But I noticed that url doesn't parse recursively:
RbbCode.new.convert("[url=testing][i]This is a quote[/i][/url]")
#=> "\n<p><a href=\"testing\">[i]This is a quote[/i]</a></p>"
So I thought maybe I could produce the same error by changing https://github.com/PeteMichaud/rbbcode/blob/pete/lib/rbbcode/node_extensions.rb#L73 to:
'<a href="' + url.text_value + '">' + recursively_convert(text) + '</a>'
But it doesn't produce an error. Apparently in that context recursively_convert("[i]Text[/i]") => "[i]Text[/i]"
I don't get it, I'm lost. What do you think?
I have code tags that are terminating before the end code tag is reached it simple put the first line in between code tags.
Howdy. I'm looking for some mechanism to tell rbbcode to not strip out unrecognized markup. Currently, anything in square brackets tends to get stripped, including stuff in [code] tags and the like; I'd like it to be preserved it it's not a registered tag. Does any such option exist?
I think there is another bug in the treemaker on line 152 the methode delete_junk_breaks
elsif @schema.block_level?(node.tag_name) and child.tag_name == @schema.line_break_tag_name and node.children.last == child
if you put the whole tree in the methode you test here @schema.block_level?(node.tag_name) if the RootNode is a blockelem and there can be an methode not found exception. Because the RootNode don´t have a methode tag_name
$ sudo gem install rbbcode
Successfully installed rbbcode-0.1.2
1 gem installed
Installing ri documentation for rbbcode-0.1.2...
ERROR: While executing gem ... (Errno::ENOENT)
No such file or directory - lib
If i try to parse [list] [] one [] two [/list][u]d[/u] i get an error, undefined method `tag_name' for #RbbCode::RootNode:0x22c8434
its on line 305 in TreeMaker.rb
elsif tag_node.tag_name == current_parent.tag_name and @schema.close_twins?(tag_node.tag_name)
I haven't tried rbbcode yet, but from reading the docs, it doesn't look like you do support smiley codes like :-) or :rolleyes: to be rendered into a graphical smiley. Strictly spoken, they aren't a part of bbcode, usually you want to have both. Any plans about this? Or is it already possible?
Hi,
BBCode has the color
and size
tag. These are not supported yet by the gem and are neither filtered nor converted. I can prepare the code change, but I'd like to know your stance on this. Some examples coming up.
Scenario 1: filter everything
[color=red]Hello world[/color]
# HTML filtered => "Hello World"
# markdown filtered => "Hello World"
Scenario 2: convert to span-class
[color=red]Hello world[/color]
# HTML to span => "<span class="red">Hello World</span>"
# Markdown to span => "<span class="red">Hello World</span>"
Markdown does support having some HTML tags in the syntax, so spans can be used also for underlines:
[u]Hello world[/u]
# HTML to span => "<span class="underlined">Hello World</span>"
# Markdown to span => "<span class="underlined">Hello World</span>"
Scenario 3: convert to span-style
[color=red]Hello world[/color]
# HTML to span => "<span style="color: red;">Hello World</span>"
# Markdown to span => "<span style="color: red;">Hello World</span>"
Which of the three do you support? Personally I'd like to see Scenario 2, because with this the styling information is not lost, but is only displayed if the styling classes are made in place. People who don't want to add the styling classes won't see the styling.
I suspect there need to be minor changes to get it to work with ruby 1.9.1 but atm it fails 43/47 tests for ruby 1.9.1 and i can't figure out whats causing the problem.
[list]
[] one
[] two
[/list]
parse:
Problem: not set li for "two" element
I was trying your gem to parse bbcode and noticed that it crashed on certain user input. I stripped it down to:
[quote]this is [size]large text[/quote][/size]
This is what I get:
> text
=> "[quote]this is [size]large[/quote][/size]"
> RbbCode.new.convert(text)
NameError: undefined local variable or method `elements' for nil:NilClass
from /Users/dia/.rvm/gems/ruby-1.9.3-p125@testapp/gems/rbbcode-1.0.2/lib/rbbcode/node_extensions.rb:32:in `to_html'
from /Users/dia/.rvm/gems/ruby-1.9.3-p125@testapp/gems/rbbcode-1.0.2/lib/rbbcode.rb:37:in `convert'
from (irb):94
from /Users/dia/.rvm/gems/ruby-1.9.3-p125@testapp/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /Users/dia/.rvm/gems/ruby-1.9.3-p125@testapp/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /Users/dia/.rvm/gems/ruby-1.9.3-p125@testapp/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
What's interesting is that for supported tags, it seems to work:
[quote]this is [b]large[/quote][/b]
> text = "[quote]this is [b]large[/quote][/b]"
=> "[quote]this is [b]large[/quote][/b]"
> RbbCode.new.convert(text)
=> "\n<p>[quote]this is <strong>large[/quote]</strong></p>"
I would expect the first input to work similarly. Although, the syntax is incorrect, at least it shouldn't crash. The output of the second example is a reasonable one.
Hi, I notice problem with [url] mark. I'm using gem 'rails', '3.2.14' and gem 'rbbcode', '~> 1.0.3'.
When I have some @group.description with [url] mark (like [url="http://facebook.com/projekt.polska.wroclaw"]Koło Wrocław na Facebooku[/url]) I get from
RbbCode.new.convert(@group.description) <p>* <a href="">Koło Wrocław na Facebooku</a></p>
Hi Jarrett,
For context, I'm writing an export tool for a phpBB forum to static markdown files. For that I'm slowly trying to catch most bbcode syntax cases that I find on the way. Some I deal in my exporter, some have there place here in the gem.
I found one thing today, I'm not entirely sure where to place.
in usual bbcode an image is described as [img]url[/url]
. phpBB3 introduced the bbcode uuid that belongs to a post and helps to group images per post. It is stored in code as [img:fpbxmhnv]url[\img:fpbxmhnv]
. More Background
This is not part of any bbcode specification or documentation and thus I wonder if the gem should support it, of if my exporter should deal with it by cleaning it before passing it to rbbcode gem.
What do you think?
There seems to be some quirkiness with lists, if I do the following (which is standard bbcode):
str = '[list][*]one [*]two [*]three [/list]'
parser = RbbCode::Parser.new
html = parser.parse(str)
The li elements get munged together and the order is lost:
<ul><li>one <li>three </li></li><li>two </li></ul>
This also happens if the list is formatted like this:
[list]
[*] One
[*] Two
[*] Three
[/list]
However, if an extra line break is added after each list item, then everything is parsed correctly. Everything also works fine if a closing [/*]
is added to list item. The problem seems to be in how the tree maker handles tags with closes_twins
in the schema, I've yet to figure out how to fix it though.
I'm working around this for now using a different custom tag but it would be terrific if you could take a look at this when you have time. I did attempt to fix it myself but I didn't have much luck.
Thanks
Hello Jarrett, the repository doesn't say anything under which license the gem is available. I'd like to make and release a fork that exports to markdown instead of HTML Do you permit that or are you interested in merging the code to this gem?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.