How to render the wiki markup obtained using MediaWiki in rails 3

895 views Asked by At

I have a page which uses the MediaWiki gem to extract wiki details and show it to the user. The user enters what they want to search for and then using MediaWiki gem I fetch the data and image.

I am able to show the images but unable to render the data as it's in wiki markup.

So what should I use? I googled and think that the redcloth gem can help me out. Should I try it or there are any other gems/logic that I am missing?

Below is the code that I am using:

my gemfile..

gem 'mediawiki-gateway'
gem 'wikipedia-client'
gem 'wikitext', '~> 2.1.1'
# gem 'red-cloth'

my controller..

  require 'media_wiki'
  require 'wikipedia'

   @page = Wikipedia.find('BMW')
   #using this parser ..should i change this>??
   @page=Wikitext::Parser.new.parse(@page.content)

my view file

<h1><%= @page.title%></h1>

<div id="image_container">  
    <% @page.image_urls[1..3].each do |image| %>


    <%= image_tag(image) %>
    <% end %>
</div>

<div id="content_class">

    <%=h @page.html_safe %>
</div>
<!-- purposely usign html safe as without it the view looks really bad(atleast now i can see the links highlighted in blue color) -->

A quick view of what my problem is---please refer the attached imageenter image description here

I want to improve the UI. How can i do it?

1

There are 1 answers

0
Nemo On

Please don't parse wikitext yourself. The TextExtracts and PageImages web APIs exist for a reason. There's plenty of web API client libraries too.