Commit 356b6c88 authored by aggsol's avatar aggsol 🙉

get data from image

parent 4813bc8c
......@@ -29,11 +29,13 @@ namespace
enum class State
{
Start,
Tag,
File,
AltTxt,
Done
};
State state = State::Start;
char last = 0;
for(int i=0; i<input.size(); ++i)
{
......@@ -43,16 +45,45 @@ namespace
{
peek = input[i+1];
}
switch(state)
{
case State::Start:
if(c == ':')
{
state = State::File;
}
break;
case State::File:
if(c == '[')
{
state = State::AltTxt;
}
else if(c != ':')
{
outFilename += c;
}
break;
case State::AltTxt:
if(c == ']')
{
state = State::Done;
}
else
{
altTxt += c;
}
break;
}
last = c;
}
if(state != State::Done)
{
return -1;
}
return 0;
}
}
......@@ -148,6 +179,28 @@ void Parser::parseLine(const std::string& line, std::map<int, Section>& sections
}
else if(i == 0 && line.substr(0, 6) == "image:")
{
std::string filename;
std::string altTxt;
if(parseImageLine(line, filename, altTxt) != 0)
{
throw std::runtime_error("Cannot parse image");
}
if(filename.empty())
{
throw std::runtime_error("Missing image filename");
}
if(altTxt.empty())
{
sections[m_currSection].m_classes.insert(filename);
}
else
{
sections[m_currSection].m_classes.insert(altTxt);
}
m_lastLine = LineType::Image;
state = State::Done;
}
......@@ -224,6 +277,7 @@ void Parser::parseLine(const std::string& line, std::map<int, Section>& sections
value += c;
}
break;
case State::SectionTitle:
addLine = false;
if(c == '=')
......@@ -264,6 +318,7 @@ void Parser::parseLine(const std::string& line, std::map<int, Section>& sections
throw std::runtime_error("Invalid section header");
}
break;
case State::DataStart:
if(c == '.')
{
......@@ -281,6 +336,7 @@ void Parser::parseLine(const std::string& line, std::map<int, Section>& sections
throw std::runtime_error("Invalid attribute. Missing '[' or '.'");
}
break;
case State::Anchor:
if(c == ']')
{
......
......@@ -28,12 +28,13 @@ public:
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());
TINY_ASSERT_EQUAL(1, sections[1].m_classes.size());
TINY_ASSERT_OK(sections[1].m_classes.find("images/example01.png") != sections[1].m_classes.end());
TINY_ASSERT_EQUAL(1, sections[2].m_classes.size());
TINY_ASSERT_OK(sections[2].m_classes.find("Hello again!") != sections[2].m_classes.end());
}
static void stylesection()
......
......@@ -6,4 +6,4 @@ text
[[section-2]]
=== 2
image::images/example02.png[]
\ No newline at end of file
image::images/example02.png[Hello again!]
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