Commit ddcfe41e authored by aggsol's avatar aggsol 🙉

detect image lines

parent b940f9c9
......@@ -83,8 +83,9 @@ void Parser::parseLine(const std::string& line, std::map<int, Section>& sections
switch(state)
{
case State::Start:
if(c == '/')
if(i == 0 && c == '/')
{
addLine = false;
state = State::CommentStart;
if(m_lastLine == LineType::Anchor)
{
......@@ -110,6 +111,11 @@ void Parser::parseLine(const std::string& line, std::map<int, Section>& sections
{
state = State::ReferenceStart;
}
else if(i == 0 && line.substr(0, 6) == "image:")
{
m_lastLine = LineType::Image;
state = State::Done;
}
else
{
if(m_lastLine == LineType::Anchor)
......
......@@ -47,7 +47,8 @@ private:
{
Other = 0,
Anchor = 1,
Section = 2
Section = 2,
Image = 3
};
LineType m_lastLine = LineType::Other;
......
......@@ -3,6 +3,7 @@
#include "../src/Parser.hpp"
#include <string>
#include <stdexcept>
#include <iostream>
class ParserTest : public tiny::Unit
{
......@@ -10,12 +11,31 @@ public:
ParserTest()
: tiny::Unit(__FILE__)
{
tiny::Unit::registerTest(&ParserTest::image, "image");
tiny::Unit::registerTest(&ParserTest::stylesection, "stylesection");
tiny::Unit::registerTest(&ParserTest::badheader, "badheader");
tiny::Unit::registerTest(&ParserTest::badref, "badref");
tiny::Unit::registerTest(&ParserTest::classes, "classes");
}
static void image()
{
bodhi::Parser parser("../test/image.adoc");
std::map<int, bodhi::Section> sections;
bool error = parser.parse(sections);
TINY_ASSERT_OK(not error);
TINY_ASSERT_EQUAL(2, sections.size());
// for(auto l: sections[1].m_lines)
// {
// std::cout << '"' << l << "\"\n";
// }
TINY_ASSERT_EQUAL(4, sections[1].m_lines.size());
}
static void stylesection()
{
bodhi::Parser parser("../test/stylesection.adoc");
......@@ -24,6 +44,7 @@ public:
bool error = parser.parse(sections);
TINY_ASSERT_OK(not error);
TINY_ASSERT_EQUAL(2, sections.size());
}
static void badheader()
......
[[section-1]]
=== 1
text
image::images/example01.png[]
text
[[section-2]]
=== 2
image::images/example02.png[]
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment