From e3ff2331adb71db3685490ec42974027fc6ca592 Mon Sep 17 00:00:00 2001 From: Yessiest Date: Wed, 30 Nov 2022 12:16:45 +0400 Subject: [PATCH] yes --- .solargraph.yml | 22 ++++++++++++ markdown.rb | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ test.rb | 7 ++++ 3 files changed, 123 insertions(+) create mode 100644 .solargraph.yml create mode 100644 markdown.rb create mode 100644 test.rb diff --git a/.solargraph.yml b/.solargraph.yml new file mode 100644 index 0000000..a61397b --- /dev/null +++ b/.solargraph.yml @@ -0,0 +1,22 @@ +--- +include: +- "**/*.rb" +exclude: +- spec/**/* +- test/**/* +- vendor/**/* +- ".bundle/**/*" +require: ["minitest"] +domains: [] +reporters: +- rubocop +- require_not_found +formatter: + rubocop: + cops: safe + except: [] + only: [] + extra_args: [] +require_paths: [] +plugins: [] +max_files: 5000 diff --git a/markdown.rb b/markdown.rb new file mode 100644 index 0000000..32f2fcb --- /dev/null +++ b/markdown.rb @@ -0,0 +1,94 @@ +## Filter-based Markdown translator. +module Markdown + ## Translator for linear tags in Markdown. + # A linear tag is any tag that starts anywhere on the line, and closes on the same exact line. + class LinearTagTranslator + def initialize(text) + @input = text + end + def escape(text) + text.sub /([*`~_!\[])/,"\\\1" + end + def to_html + @input + # Newline + .sub /\s{2}[\n\r]/,"
" + # Inline code (discord style) + .sub /(?#{self.escape code}" + } + # Inline code (Markdown style) + .sub /(?#{self.escape code}" + } + # Bold-italics + .sub /(?\1" + # Bold + .sub /(?\1" + # Italics + .sub /(?\1" + # Strikethrough + .sub /(?\1" + # Underline + .sub /(?\1" + # Image + .sub /(?" + # Link + .sub /(?\1" + end + end + ## Translator for linear leftmost tags. + # Leftmost linear tags open on the leftmost end of the string, and close once the line ends. These tags do not need to be explicitly closed. + class LeftmostTagTranslator + def initalize(text) + @input = text + end + def to_html + # Headers + @input.sub(/(?"+content+"" + } + end + end + ## Translator for code blocks in Markdown. + # First in terms of precedence. + class CodeBlocksTranslator + def initialize(text + end + ## Translator for quotes in Markdown. + # These deserve their own place in hell. + class QuoteTranslator + def initialize(text, level: 0) + if text.is_a? Array then + @lines = text + elsif text.is_a? String then + @lines = text.split("\n\n") + end + end + def to_html + stack = [] + range = [] + state = false + @lines.each_with_index { |x,index| + if x.match(/^\s{0,1}>/) and state == false then + range.append index + state = true + end + if (not x.match /^\s{0,1}>/) and state == true then + range.append index-1 + state = false + stack.append(range[0]..range[1]) + range = [] + end + } + range.each { |r| + @lines[r] = QuoteTranslator.new(@lines[r]).to_html + } + @lines = @lines.map { |x| + (x.sub /^\s{0,1}>/,"") + } + end + end +end + + diff --git a/test.rb b/test.rb new file mode 100644 index 0000000..14eb156 --- /dev/null +++ b/test.rb @@ -0,0 +1,7 @@ +require "minitest" +require "markdown" +class LinearParsingTest << Minitest::Test + def setup + @lparser = + +