Nexmo / nexmo-markdown-renderer

Nexmo Markdown Renderer
MIT License
2 stars 1 forks source link

Fix string interpolation error #35

Closed shreyas44 closed 3 years ago

shreyas44 commented 4 years ago

There was an error with the string interpolation, which resulted in the string "#{alt_text}" being rendered rather than the value of the _alt_text variable.

Closes #30

shreyas44 commented 4 years ago

Hi @bencgreenberg! I created a small test script to parse a markdown file. However, I'm not able to figure out how the markdown renderer parses the path for the image. I'm parsing the markdown file from the nexmo docs.

The path for the image is given as below Screen Shot 2020-10-26 at 11 57 13 PM

How do I specify the path for the image? Because, specifying the relative path from the ruby test script didn't work and neither did the absolute path.

Currently the output for that part is:

<h2
  id="missing-image"
  data-id="b63fc9bcbc5d4c06af6373310370009b"
  class="Vlt-title--icon"
>
  <a href="#missing-image" class="heading-permalink">
    <svg class="Vlt-grey">
      <use xlink:href="/symbol/volta-icons.svg#Vlt-icon-link"></use>
    </svg>
  </a>
  Missing image
</h2>
hummusonrails commented 4 years ago

Hi @bencgreenberg! I created a small test script to parse a markdown file. However, I'm not able to figure out how the markdown renderer parses the path for the image. I'm parsing the markdown file from the nexmo docs.

The path for the image is given as below Screen Shot 2020-10-26 at 11 57 13 PM

How do I specify the path for the image? Because, specifying the relative path from the ruby test script didn't work and neither did the absolute path.

Currently the output for that part is:

<h2
  id="missing-image"
  data-id="b63fc9bcbc5d4c06af6373310370009b"
  class="Vlt-title--icon"
>
  <a href="#missing-image" class="heading-permalink">
    <svg class="Vlt-grey">
      <use xlink:href="/symbol/volta-icons.svg#Vlt-icon-link"></use>
    </svg>
  </a>
  Missing image
</h2>

Hey @shreyas44, good question. You can use one of the markdown files in the fixtures directory to mock the data instead of calling to production data. The output you shared above looks like what the renderer will do, which is to convert markdown into HTML. However, there needs to be a environment variable set, DOCS_BASE_PATH equal to the top level directory of the documentation, something like DOCS_BASE_PATH=. might do it, if you're there already.

shreyas44 commented 4 years ago

Hey @bencgreenberg, I tried setting the DOCS_BASE_PATH to the the root directory by executing export DOCS_BASE_PATH=. (also tried the absolute path). It still doesn't seem to work. Also, I tried specifying the path to the Markdown files as specified in the README of this repository, and the renderer parses the path as a plain string.

My current directory structure:

...
lib/
  ...
  nexmo_markdown_renderer.rb
public/
  ...
  screenshots/
    smsInboundWebhook.png

test.rb

The DOCS_BASE_PATH env variable is set to .

And the test.rb file looks like this

require_relative 'lib/nexmo_markdown_renderer'

content = Nexmo::Markdown::Renderer.new()
markdown = # a string containing the markdown

rendered = content.call(markdown)
File.write('test.html', rendered)
hummusonrails commented 4 years ago

I tried setting the DOCS_BASE_PATH to the the root directory by executing export DOCS_BASE_PATH=. (also tried the absolute path). It still doesn't seem to work. Also, I tried specifying the path to the Markdown files as specified in the README of this repository, and the renderer parses the path as a plain string.

My current directory structure:

...
lib/
  ...
  nexmo_markdown_renderer.rb
public/
  ...
  screenshots/
    smsInboundWebhook.png

test.rb

The DOCS_BASE_PATH env variable is set to .

And the test.rb file looks like this

require_relative 'lib/nexmo_markdown_renderer'

content = Nexmo::Markdown::Renderer.new()
markdown = # a string containing the markdown

rendered = content.call(markdown)
File.write('test.html', rendered)

Hrmm... good question. @fabianrbz , who wrote most of this library might be able to offer some quick advice when he starts his day tomorrow.

shreyas44 commented 4 years ago

Hrmm... good question. @fabianrbz , who wrote most of this library might be able to offer some quick advice when he starts his day tomorrow.

Alright then!

fabianrbz commented 4 years ago

@shreyas44 @bencgreenberg something like this will do it:

spec/filters/markdown_filter_spec.rb

require 'spec_helper'

RSpec.describe Nexmo::Markdown::MarkdownFilter do
  describe '#call' do
    subject { described_class.call(input) }

    context 'converting images' do
      let(:input) do
        "![Markdown Image Alt Text](/images/example.png 'Markdown Image Title')"
      end

      it 'converts markdown images into image tags' do
        expect(subject).to eq('<p><figure><img src="/images/example.png" alt="Markdown Image Alt Text"></figure></p>')
      end
    end
  end
end
shreyas44 commented 3 years ago

@shreyas44 @bencgreenberg something like this will do it:

spec/filters/markdown_filter_spec.rb

require 'spec_helper'

RSpec.describe Nexmo::Markdown::MarkdownFilter do
  describe '#call' do
    subject { described_class.call(input) }

    context 'converting images' do
      let(:input) do
        "![Markdown Image Alt Text](/images/example.png 'Markdown Image Title')"
      end

      it 'converts markdown images into image tags' do
        expect(subject).to eq('<p><figure><img src="/images/example.png" alt="Markdown Image Alt Text"></figure></p>')
      end
    end
  end
end

@fabianrbz I've never worked with Ruby before so forgive me. I created the file at spec/filters/markdown_filter_spec.rb and copy pasted the code you wrote. I tried running the file with ruby markdown_filter_spec.rb and bundle exec ruby markdown_filter_spec.rb but both times I got an error telling require': cannot load such file -- spec_helper (LoadError), which I'm assuming means the file/module wasn't found ruby.

I've already run bundle install which ran successfully. Is there a prerequisite command I should have run before trying to execute this, or is there something else I'm doing wrong?

fabianrbz commented 3 years ago

@shreyas44 in order to run the specs you should run: bundle exec rspec

shreyas44 commented 3 years ago

@fabianrbz The test executed successfully with the following response:

Finished in 0.05302 seconds (files took 3.9 seconds to load)
1 example, 0 failures
fabianrbz commented 3 years ago

@shreyas44 awesome, you can also commit the test and see its output here. One of our checks runs all the tests.

shreyas44 commented 3 years ago

@shreyas44 awesome, you can also commit the test and see its output here. One of our checks runs all the tests.

Just did that!