link decomp, tag cache, image capture
This commit is contained in:
parent
e7dd0a7886
commit
70a4c5ee4a
@ -3,6 +3,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
static const std::string MD_LINK_REGEX = R"(\[.*?\]\(.*?\))";
|
static const std::string MD_LINK_REGEX = R"(\[.*?\]\(.*?\))";
|
||||||
static const std::string MD_MD_LINK_REGEX = R"(\[.*?\]\(.*?\.md\))";
|
static const std::string MD_MD_LINK_REGEX = R"(\[.*?\]\(.*?\.md(#.*?)*\))";
|
||||||
static const std::string MD_IMAGE_LINK_REGEX = R"(!\[.*?\]\(.*?\.png\))";
|
static const std::string MD_IMAGE_LINK_REGEX = R"(!\[.*?\]\(.*?\.png\))";
|
||||||
static const std::string MD_TAG_REGEX = R"(#{1}[^\s#.]+)";
|
static const std::string MD_TAG_REGEX = R"((^|[[:blank:]])#{1}[^\s#.]+)";
|
19
src/main.cpp
19
src/main.cpp
@ -33,14 +33,29 @@ int main(int argc, const char *argv[]) {
|
|||||||
|
|
||||||
auto context = file_cache.get()[(*config)["index"].as<int>()];
|
auto context = file_cache.get()[(*config)["index"].as<int>()];
|
||||||
|
|
||||||
std::cout << context->file_entry.get_content() << std::endl << std::endl << std::endl;
|
std::cout << context->file_entry->get_content() << std::endl << std::endl << std::endl;
|
||||||
|
|
||||||
std::cout << "links: " << context->links.size() << std::endl;
|
std::cout << "links: " << context->links.size() << std::endl;
|
||||||
|
std::cout << "images: " << context->images.size() << std::endl;
|
||||||
std::cout << "tags: " << context->tags.size() << std::endl << std::endl << std::endl;;
|
std::cout << "tags: " << context->tags.size() << std::endl << std::endl << std::endl;;
|
||||||
|
|
||||||
for (auto link : context->links)
|
for (auto link : context->links)
|
||||||
{
|
{
|
||||||
std::cout << link.original_form << std::endl;
|
std::cout << link.original_form << " " << link.display << " --- " << link.link << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "tag cache: " << file_cache.tag_map.size() << std::endl;
|
||||||
|
|
||||||
|
for (auto tag : file_cache.tag_map)
|
||||||
|
{
|
||||||
|
std::cout << tag.first << ": ";
|
||||||
|
|
||||||
|
for (auto tag_entry: tag.second)
|
||||||
|
{
|
||||||
|
std::cout << tag_entry->relative_path << ", ";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,23 +3,24 @@
|
|||||||
namespace kc {
|
namespace kc {
|
||||||
|
|
||||||
FileContext::FileContext(kc::FileEntry entry)
|
FileContext::FileContext(kc::FileEntry entry)
|
||||||
: file_entry(entry)
|
: file_entry(std::make_shared<kc::FileEntry>(entry))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileContext::parse()
|
void FileContext::parse()
|
||||||
{
|
{
|
||||||
if (!file_entry.content_loaded())
|
if (!file_entry->content_loaded())
|
||||||
{
|
{
|
||||||
throw std::logic_error("cannot parse from file entry as it has not been loaded");
|
throw std::logic_error("cannot parse from file entry as it has not been loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
links.clear();
|
links.clear();
|
||||||
|
images.clear();
|
||||||
tags.clear();
|
tags.clear();
|
||||||
|
|
||||||
std::regex link_regex(MD_MD_LINK_REGEX);
|
std::regex link_regex(MD_MD_LINK_REGEX);
|
||||||
std::string file_content = file_entry.get_content();
|
std::string file_content = file_entry->get_content();
|
||||||
std::smatch link_match;
|
std::smatch link_match;
|
||||||
while(std::regex_search(file_content, link_match, link_regex)) {
|
while(std::regex_search(file_content, link_match, link_regex)) {
|
||||||
|
|
||||||
@ -27,12 +28,21 @@ void FileContext::parse()
|
|||||||
file_content = link_match.suffix();
|
file_content = link_match.suffix();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::regex tag_regex(MD_TAG_REGEX);
|
std::regex image_regex(MD_IMAGE_LINK_REGEX);
|
||||||
file_content = file_entry.get_content();
|
file_content = file_entry->get_content();
|
||||||
|
std::smatch image_match;
|
||||||
|
while(std::regex_search(file_content, image_match, image_regex)) {
|
||||||
|
|
||||||
|
images.push_back(image_match.str());
|
||||||
|
file_content = image_match.suffix();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::regex tag_regex(MD_TAG_REGEX, std::regex::multiline);
|
||||||
|
file_content = file_entry->get_content();
|
||||||
std::smatch tag_match;
|
std::smatch tag_match;
|
||||||
while(std::regex_search(file_content, tag_match, tag_regex)) {
|
while(std::regex_search(file_content, tag_match, tag_regex)) {
|
||||||
|
|
||||||
tags.push_back(tag_match.str());
|
tags.push_back(tag_match.str().substr(1));
|
||||||
file_content = tag_match.suffix();
|
file_content = tag_match.suffix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
#include "../fs/FileEntry.hpp"
|
#include "../fs/FileEntry.hpp"
|
||||||
@ -14,8 +15,9 @@ class FileContext {
|
|||||||
|
|
||||||
FileContext(kc::FileEntry entry);
|
FileContext(kc::FileEntry entry);
|
||||||
|
|
||||||
kc::FileEntry file_entry;
|
std::shared_ptr<kc::FileEntry> file_entry;
|
||||||
std::vector<kc::Link> links;
|
std::vector<kc::Link> links;
|
||||||
|
std::vector<kc::Link> images;
|
||||||
std::vector<std::string> tags;
|
std::vector<std::string> tags;
|
||||||
|
|
||||||
void parse();
|
void parse();
|
||||||
|
@ -25,11 +25,20 @@ void FileContextCache::load(std::string root_path)
|
|||||||
|
|
||||||
void FileContextCache::parse_all()
|
void FileContextCache::parse_all()
|
||||||
{
|
{
|
||||||
|
tag_map.clear();
|
||||||
for (auto context: file_contexts)
|
for (auto context: file_contexts)
|
||||||
{
|
{
|
||||||
if (context->file_entry.relative_path.extension() == ".md")
|
if (context->file_entry->relative_path.extension() == ".md")
|
||||||
{
|
{
|
||||||
context->parse();
|
context->parse();
|
||||||
|
|
||||||
|
if (context->tags.size() != 0)
|
||||||
|
{
|
||||||
|
for (auto tag : context->tags)
|
||||||
|
{
|
||||||
|
tag_map[tag].push_back(context->file_entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include "FileContext.hpp"
|
#include "FileContext.hpp"
|
||||||
|
|
||||||
namespace kc {
|
namespace kc {
|
||||||
@ -14,6 +16,8 @@ class FileContextCache {
|
|||||||
std::vector<std::shared_ptr<kc::FileContext>> get();
|
std::vector<std::shared_ptr<kc::FileContext>> get();
|
||||||
void parse_all();
|
void parse_all();
|
||||||
|
|
||||||
|
std::unordered_map<std::string, std::vector<std::shared_ptr<kc::FileEntry>>> tag_map;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::shared_ptr<kc::FileContext>> file_contexts;
|
std::vector<std::shared_ptr<kc::FileContext>> file_contexts;
|
||||||
};
|
};
|
||||||
|
@ -3,9 +3,25 @@
|
|||||||
namespace kc {
|
namespace kc {
|
||||||
|
|
||||||
Link::Link(std::string original)
|
Link::Link(std::string original)
|
||||||
: original_form(original)
|
|
||||||
{
|
{
|
||||||
|
original_form = std::regex_replace(original, std::regex("%20"), " ");
|
||||||
|
|
||||||
|
auto opening_display = original_form.find('[');
|
||||||
|
auto closing_display = original_form.find(']', opening_display);
|
||||||
|
|
||||||
|
display = original_form.substr(opening_display + 1, closing_display - opening_display - 1);
|
||||||
|
|
||||||
|
auto opening_link = closing_display + 1;
|
||||||
|
auto closing_link = original_form.rfind(')');
|
||||||
|
|
||||||
|
link = original_form.substr(opening_link + 1, closing_link - opening_link - 1);
|
||||||
|
|
||||||
|
auto display_pos = original_form.find('#', opening_link);
|
||||||
|
|
||||||
|
if(display_pos != std::string::npos)
|
||||||
|
{
|
||||||
|
display = original_form.substr(display_pos + 1, closing_link - display_pos - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
namespace kc {
|
namespace kc {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user