Closed shreyas44 closed 3 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
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>
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
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.
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)
I tried setting the
DOCS_BASE_PATH
to the the root directory by executingexport 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 thisrequire_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.
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!
@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
""
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 @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 "" 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?
@shreyas44 in order to run the specs you should run:
bundle exec rspec
@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
@shreyas44 awesome, you can also commit the test and see its output here. One of our checks runs all the tests.
@shreyas44 awesome, you can also commit the test and see its output here. One of our checks runs all the tests.
Just did that!
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