From lists at ruby-forum.com Thu Aug 5 12:49:28 2010 From: lists at ruby-forum.com (James King) Date: Thu, 5 Aug 2010 18:49:28 +0200 Subject: Stripping textile markup Message-ID: <87250ea61028d54e4bf0e3a97b69fe03@ruby-forum.com> Hello, I have come across certain situations where text marked up with textile syntax needs to be displayed where HTML isn't wanted. For example, in the title element of a an HTML page. In these situations, I would like a way of stripping away the textile markup from a string and displaying it completely "naked" - without HTML tags and, crucially, without the textile markup too. So: >> The _quick_ brown "fox":/fox.html jumps over the *lazy* dog's tail. becomes >> The quick brown fox jumps over the lazy dog?s tail. (N.B. In the example above, I still want my punctuation made pretty "dog's tail" should still become "dog?s tail" ) What's the best way of doing this? If there isn't an elegant way of doing it, could Redcloth have a to_plaintext method? Thanks, - James -- Posted via http://www.ruby-forum.com/. From judofyr at gmail.com Thu Aug 5 13:04:17 2010 From: judofyr at gmail.com (Magnus Holm) Date: Thu, 5 Aug 2010 19:04:17 +0200 Subject: Stripping textile markup In-Reply-To: <87250ea61028d54e4bf0e3a97b69fe03@ruby-forum.com> References: <87250ea61028d54e4bf0e3a97b69fe03@ruby-forum.com> Message-ID: You could use Nokogiri: require 'redcloth' require 'nokogiri' html = RedCloth.new(str).to_html plaintext = Nokogiri::HTML.fragment(html).text // Magnus Holm On Thu, Aug 5, 2010 at 18:49, James King wrote: > Hello, > > I have come across certain situations where text marked up with textile > syntax needs to be displayed where HTML isn't wanted. For example, in > the title element of a an HTML page. > > In these situations, I would like a way of stripping away the textile > markup from a string and displaying it completely "naked" - without HTML > tags and, crucially, without the textile markup too. > > So: > >>> The _quick_ brown "fox":/fox.html jumps over the *lazy* dog's tail. > > becomes > >>> The quick brown fox jumps over the lazy dog?s tail. > > (N.B. In the example above, I still want my punctuation made pretty > "dog's tail" should still become "dog?s tail" ) > > What's the best way of doing this? If there isn't an elegant way of > doing it, could Redcloth have a to_plaintext method? > > Thanks, > > - James > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Redcloth-upwards mailing list > Redcloth-upwards at rubyforge.org > http://rubyforge.org/mailman/listinfo/redcloth-upwards From lists at ruby-forum.com Thu Aug 5 13:54:17 2010 From: lists at ruby-forum.com (James King) Date: Thu, 5 Aug 2010 19:54:17 +0200 Subject: Stripping textile markup In-Reply-To: References: <87250ea61028d54e4bf0e3a97b69fe03@ruby-forum.com> Message-ID: <878208b46ba556ba179b199d6a13023a@ruby-forum.com> Thanks Magnus! Magnus Holm wrote: > You could use Nokogiri: > > require 'redcloth' > require 'nokogiri' > > html = RedCloth.new(str).to_html > plaintext = Nokogiri::HTML.fragment(html).text > > // Magnus Holm This works nicely. Have also found an example using Hpricot http://wiki.github.com/hpricot/hpricot/hpricot-challenge (see under "Strip All HTML Tags"). I'm happy using this, but I'm still left wondering whether it would make more sense for RedCloth to have an elegant "to_plaintext" method. It seems better not to go through an HTML intermediate stage. Best, - James -- Posted via http://www.ruby-forum.com/. From jg at jasongarber.com Sun Aug 8 07:20:42 2010 From: jg at jasongarber.com (Jason Garber) Date: Sun, 8 Aug 2010 07:20:42 -0400 Subject: Stripping textile markup In-Reply-To: References: <87250ea61028d54e4bf0e3a97b69fe03@ruby-forum.com> Message-ID: That's a simple, elegant solution! I was going to suggest writing your own formatter that passed everything through without adding anything, but that's way too much work! On Aug 5, 2010, at 1:04 PM, Magnus Holm wrote: > You could use Nokogiri: > > require 'redcloth' > require 'nokogiri' > > html = RedCloth.new(str).to_html > plaintext = Nokogiri::HTML.fragment(html).text > > // Magnus Holm > > > > On Thu, Aug 5, 2010 at 18:49, James King wrote: >> Hello, >> >> I have come across certain situations where text marked up with textile >> syntax needs to be displayed where HTML isn't wanted. For example, in >> the title element of a an HTML page. >> >> In these situations, I would like a way of stripping away the textile >> markup from a string and displaying it completely "naked" - without HTML >> tags and, crucially, without the textile markup too. >> >> So: >> >>>> The _quick_ brown "fox":/fox.html jumps over the *lazy* dog's tail. >> >> becomes >> >>>> The quick brown fox jumps over the lazy dog?s tail. >> >> (N.B. In the example above, I still want my punctuation made pretty >> "dog's tail" should still become "dog?s tail" ) >> >> What's the best way of doing this? If there isn't an elegant way of >> doing it, could Redcloth have a to_plaintext method? >> >> Thanks, >> >> - James >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Redcloth-upwards mailing list >> Redcloth-upwards at rubyforge.org >> http://rubyforge.org/mailman/listinfo/redcloth-upwards > _______________________________________________ > Redcloth-upwards mailing list > Redcloth-upwards at rubyforge.org > http://rubyforge.org/mailman/listinfo/redcloth-upwards From judofyr at gmail.com Tue Aug 10 16:08:17 2010 From: judofyr at gmail.com (Magnus Holm) Date: Tue, 10 Aug 2010 22:08:17 +0200 Subject: Stripping textile markup In-Reply-To: References: <87250ea61028d54e4bf0e3a97b69fe03@ruby-forum.com> Message-ID: You should probably add that as a TODO, since I've seen plenty of sites who uses the Textile source as a simple plaintext-preview (where a proper formatter would definitely be better). // Magnus Holm On Sun, Aug 8, 2010 at 13:20, Jason Garber wrote: > That's a simple, elegant solution! ?I was going to suggest writing your own formatter that passed everything through without adding anything, but that's way too much work! > > On Aug 5, 2010, at 1:04 PM, Magnus Holm wrote: > >> You could use Nokogiri: >> >> ? ?require 'redcloth' >> ? ?require 'nokogiri' >> >> ? ?html = RedCloth.new(str).to_html >> ? ?plaintext = Nokogiri::HTML.fragment(html).text >> >> // Magnus Holm >> >> >> >> On Thu, Aug 5, 2010 at 18:49, James King wrote: >>> Hello, >>> >>> I have come across certain situations where text marked up with textile >>> syntax needs to be displayed where HTML isn't wanted. For example, in >>> the title element of a an HTML page. >>> >>> In these situations, I would like a way of stripping away the textile >>> markup from a string and displaying it completely "naked" - without HTML >>> tags and, crucially, without the textile markup too. >>> >>> So: >>> >>>>> The _quick_ brown "fox":/fox.html jumps over the *lazy* dog's tail. >>> >>> becomes >>> >>>>> The quick brown fox jumps over the lazy dog?s tail. >>> >>> (N.B. In the example above, I still want my punctuation made pretty >>> "dog's tail" should still become "dog?s tail" ) >>> >>> What's the best way of doing this? If there isn't an elegant way of >>> doing it, could Redcloth have a to_plaintext method? >>> >>> Thanks, >>> >>> - James >>> -- >>> Posted via http://www.ruby-forum.com/. >>> _______________________________________________ >>> Redcloth-upwards mailing list >>> Redcloth-upwards at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/redcloth-upwards >> _______________________________________________ >> Redcloth-upwards mailing list >> Redcloth-upwards at rubyforge.org >> http://rubyforge.org/mailman/listinfo/redcloth-upwards > > _______________________________________________ > Redcloth-upwards mailing list > Redcloth-upwards at rubyforge.org > http://rubyforge.org/mailman/listinfo/redcloth-upwards > From ibc at aliax.net Sun Aug 29 13:59:39 2010 From: ibc at aliax.net (=?UTF-8?Q?I=C3=B1aki_Baz_Castillo?=) Date: Sun, 29 Aug 2010 19:59:39 +0200 Subject:
with multiple
Message-ID: Hi, I basically want to get this HTML output: -------------------------
Paragraphs
First paragraph.
Second paragraph.
------------------------- In this way, I can add a vertical separation (margin-top) between both paragraphs. However using RedCloth I cannot get it: ---------------------------- - Paragraphs := First paragraph. Second paragraph. ---------------------------- maps to: ----------------------------
Paragraphs
First paragraph.
Second paragraph.
---------------------------- RedCloth inserts a
so it's not possible to simulate a vertical separation with N pixels between both "paragraphs". Is there a workaround for achieving it? Thanks a lot. -- I?aki Baz Castillo From ibc at aliax.net Sun Aug 29 14:02:22 2010 From: ibc at aliax.net (=?UTF-8?Q?I=C3=B1aki_Baz_Castillo?=) Date: Sun, 29 Aug 2010 20:02:22 +0200 Subject: Possible bug when using definition list with no body Message-ID: Hi, the following incomplete definition list breaks the rest of the textile document: ------------------------ - hello := h1. Title some text. ----------------------- maps to: -----------------------
hello
------------------------ As you can see,
is not terminated. Is it a bug? Regards. -- I?aki Baz Castillo