Restructured the repo
This commit is contained in:
parent
bf00a34512
commit
a4242dcac9
|
@ -1,7 +1,8 @@
|
||||||
#!/usr/bin/ruby
|
#!/usr/bin/ruby
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative 'document'
|
require 'optparse'
|
||||||
|
require 'rbmark'
|
||||||
require 'io/console'
|
require 'io/console'
|
||||||
require 'io/console/size'
|
require 'io/console/size'
|
||||||
|
|
||||||
|
@ -191,7 +192,6 @@ module MDPP
|
||||||
|
|
||||||
# Long bracket for code blocks
|
# Long bracket for code blocks
|
||||||
def longbracket(text, properties)
|
def longbracket(text, properties)
|
||||||
puts properties.inspect
|
|
||||||
textlines = text.lines
|
textlines = text.lines
|
||||||
textlines = textlines.map do |line|
|
textlines = textlines.map do |line|
|
||||||
"│ #{line}"
|
"│ #{line}"
|
||||||
|
@ -203,6 +203,8 @@ module MDPP
|
||||||
|
|
||||||
# Add text to bibliography
|
# Add text to bibliography
|
||||||
def bibliography(text, properties)
|
def bibliography(text, properties)
|
||||||
|
return "#{text}[#{properties['element'][:link]}]" if @options['nb']
|
||||||
|
|
||||||
@bibliography.append([text, properties['element'][:link]])
|
@bibliography.append([text, properties['element'][:link]])
|
||||||
"#{text}[#{@bibliography.length + 1}]"
|
"#{text}[#{@bibliography.length + 1}]"
|
||||||
end
|
end
|
||||||
|
@ -318,10 +320,9 @@ module MDPP
|
||||||
# @param options [Hash]
|
# @param options [Hash]
|
||||||
def initialize(input, options)
|
def initialize(input, options)
|
||||||
@doc = RBMark::DOM::Document.parse(input)
|
@doc = RBMark::DOM::Document.parse(input)
|
||||||
@color_mode = options.fetch("color", true)
|
|
||||||
@ansi_mode = options.fetch("ansi", true)
|
|
||||||
@style = ::MDPP::DEFAULT_STYLE.dup
|
@style = ::MDPP::DEFAULT_STYLE.dup
|
||||||
@bibliography = []
|
@bibliography = []
|
||||||
|
@options = options
|
||||||
return unless options['style']
|
return unless options['style']
|
||||||
|
|
||||||
@style = @style.map do |k, v|
|
@style = @style.map do |k, v|
|
||||||
|
@ -334,7 +335,8 @@ module MDPP
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def render
|
def render
|
||||||
text = _render(@doc.children, @doc.properties)
|
text = _render(@doc.children, @doc.properties)
|
||||||
text += _render_bibliography unless @bibliography.empty?
|
text += _render_bibliography unless @bibliography.empty? or
|
||||||
|
@options['nb']
|
||||||
text
|
text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -342,7 +344,7 @@ module MDPP
|
||||||
|
|
||||||
def _render_bibliography
|
def _render_bibliography
|
||||||
size = IO.console.winsize[1]
|
size = IO.console.winsize[1]
|
||||||
text = "\n#{('─' * size)}\n"
|
text = "\n#{'─' * size}\n"
|
||||||
text += @bibliography.map.with_index do |element, index|
|
text += @bibliography.map.with_index do |element, index|
|
||||||
"- [#{index + 1}] #{wordwrap(element.join(': '), size - 15)}"
|
"- [#{index + 1}] #{wordwrap(element.join(': '), size - 15)}"
|
||||||
end.join("\n")
|
end.join("\n")
|
||||||
|
@ -426,8 +428,52 @@ module MDPP
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if __FILE__ == $0
|
options = {}
|
||||||
text = $stdin.read
|
OptionParser.new do |opts|
|
||||||
renderer = MDPP::Renderer.new(text, {})
|
opts.banner = <<~TEXT
|
||||||
puts renderer.render
|
MDPP - Markdown PrettyPrint based on RBMark parser
|
||||||
|
Usage: mdpp [options] <file | ->
|
||||||
|
TEXT
|
||||||
|
|
||||||
|
opts.on("-h", "--help", "Prints this help message") do
|
||||||
|
puts opts
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
|
||||||
|
opts.on("-e", "--extension EXTENSION",
|
||||||
|
"require EXTENSION before parsing") do |libname|
|
||||||
|
require libname
|
||||||
|
end
|
||||||
|
|
||||||
|
opts.on(
|
||||||
|
"-c",
|
||||||
|
"--config CONFIG",
|
||||||
|
"try to load CONFIG (~/.config/mdpp.rb is loaded by default)"
|
||||||
|
) do |config|
|
||||||
|
# rubocop:disable Security/Eval
|
||||||
|
options.merge!(eval(File.read(config))) if File.exist?(config)
|
||||||
|
# rubocop:enable Security/Eval
|
||||||
|
end
|
||||||
|
|
||||||
|
opts.on(
|
||||||
|
"-b",
|
||||||
|
"--no-bibliography",
|
||||||
|
"Do not print bibliography (links, references, etc.) at the bottom"
|
||||||
|
) do
|
||||||
|
options["nb"] = true
|
||||||
|
end
|
||||||
|
end.parse!
|
||||||
|
|
||||||
|
# rubocop:disable Security/Eval
|
||||||
|
if File.exist?("#{ENV['HOME']}/.config/mdpp.rb")
|
||||||
|
options.merge!(eval(File.read("#{ENV['HOME']}/.config/mdpp.rb")))
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Security/Eval
|
||||||
|
|
||||||
|
text = if ARGV[0].nil? or ARGV[0] == "-"
|
||||||
|
$stdin.read
|
||||||
|
else
|
||||||
|
File.read(ARGV[0])
|
||||||
|
end
|
||||||
|
renderer = MDPP::Renderer.new(text, options)
|
||||||
|
puts renderer.render
|
13
classes
13
classes
|
@ -1,13 +0,0 @@
|
||||||
Bold [x}
|
|
||||||
Italics [x]
|
|
||||||
Underline [x]
|
|
||||||
Strikethrough [x]
|
|
||||||
CodeInline [x]
|
|
||||||
Link [x]
|
|
||||||
Image [x]
|
|
||||||
Headings [x]
|
|
||||||
CodeBlock [x]
|
|
||||||
QuoteBlock [x]
|
|
||||||
ULBlock [x]
|
|
||||||
OLBLock [x]
|
|
||||||
TableBlock []
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = 'rbmark'
|
||||||
|
s.version = '0.5'
|
||||||
|
s.summary = <<~SUMMARY
|
||||||
|
Modular, extensible, HTML-agnostic Markdown parser
|
||||||
|
SUMMARY
|
||||||
|
s.description = <<~TEXT
|
||||||
|
RBMark is a Markdown parser that represents Markdown in a DOM-like
|
||||||
|
object structure, allowing for other interfaces to produce more
|
||||||
|
complex translators from Markdown to any given format.
|
||||||
|
TEXT
|
||||||
|
s.authors = ['yessiest']
|
||||||
|
s.email = 'yessiest@text.512mb.org'
|
||||||
|
s.license = 'Apache-2.0'
|
||||||
|
s.homepage = 'https://adastra7.net/git/Yessiest/rubymark'
|
||||||
|
s.files = Dir['lib/**/*.rb'] + Dir['bin/*']
|
||||||
|
s.required_ruby_version = '>= 3.0.0'
|
||||||
|
s.executables = ['mdpp']
|
||||||
|
end
|
149
test.md
149
test.md
|
@ -1,149 +0,0 @@
|
||||||
# Header level sadga kjshdkj hasdkjs hakjdhakjshd kashd kjashd kjashdk asjhdkj ashdkj ahskj hdaskd haskj hdkjash dkjashd ksajdh askjd hak askjhdkasjhdaksjhd sakjd 1
|
|
||||||
|
|
||||||
> Block quote text
|
|
||||||
>
|
|
||||||
> Second block quote paragraph
|
|
||||||
> Block quote **bold** and *italics* test
|
|
||||||
> Block quote **bold *italics* mix** test
|
|
||||||
|
|
||||||
> Nested block quote test
|
|
||||||
> > with a very stupid secondary quote syntax
|
|
||||||
this should end the block quote btw
|
|
||||||
|
|
||||||
## Header level 2
|
|
||||||
|
|
||||||
also header level 2
|
|
||||||
---
|
|
||||||
|
|
||||||
also header level 1
|
|
||||||
===
|
|
||||||
|
|
||||||
not a header level2
|
|
||||||
---asdlkashdlkasjd
|
|
||||||
|
|
||||||
not a header level1
|
|
||||||
===asdajlsdkjlsd
|
|
||||||
|
|
||||||
not a header level2
|
|
||||||
---
|
|
||||||
|
|
||||||
not a header level1
|
|
||||||
===
|
|
||||||
[link](http://example.com)
|
|
||||||
![image alt text](http://example.com)
|
|
||||||
|
|
||||||
``` plaintext
|
|
||||||
code *block*
|
|
||||||
eat my shit
|
|
||||||
```
|
|
||||||
|
|
||||||
> It is also of importance to note that this code is a hello world program,
|
|
||||||
> written entirely in C++.
|
|
||||||
>
|
|
||||||
> ```cpp
|
|
||||||
> int main() {
|
|
||||||
> cout << "Hello **world!**";
|
|
||||||
> }
|
|
||||||
> ```
|
|
||||||
|
|
||||||
> theoretical failure test case
|
|
||||||
> **bold** **with space**
|
|
||||||
paragraph with ``inline code block``
|
|
||||||
|
|
||||||
- Unordered list element 1
|
|
||||||
- Unordered list element 2
|
|
||||||
|
|
||||||
1. Ordered list element 1
|
|
||||||
2. Ordered list element 2
|
|
||||||
|
|
||||||
1. [Link](https://ass.com)
|
|
||||||
2. [Lv2](https://ass.com)
|
|
||||||
3. [Lv2](https://anus.com)
|
|
||||||
4. shit
|
|
||||||
|
|
||||||
This is not a list
|
|
||||||
- because it continues the paragraph
|
|
||||||
- this is how it should be, like it or not
|
|
||||||
|
|
||||||
- This is also not a list
|
|
||||||
because there is text on the next line
|
|
||||||
|
|
||||||
- But this here is a list
|
|
||||||
because the spacing is made correctly
|
|
||||||
|
|
||||||
more so than that, there are multiple paragraphs here!
|
|
||||||
|
|
||||||
- AND even more lists in a list!
|
|
||||||
- how extra
|
|
||||||
- And this is just the next element in the list
|
|
||||||
|
|
||||||
1. same thing but with ordered lists
|
|
||||||
ordered lists have a little extra special property to them
|
|
||||||
|
|
||||||
the indentations are always symmetrical to the last space of the bullet's number
|
|
||||||
10. i.e., if you look at this here example
|
|
||||||
this will work
|
|
||||||
|
|
||||||
obviously
|
|
||||||
|
|
||||||
|
|
||||||
1. But this
|
|
||||||
10. Won't
|
|
||||||
because the indentation doesn't match the start of the line.
|
|
||||||
|
|
||||||
generally speaking this kind of insane syntax trickery won't be necessary,
|
|
||||||
but it's just better to have standards than to have none of them.
|
|
||||||
|
|
||||||
an unfortunate side effect of this flexibility should also be noted, and
|
|
||||||
it's that markdown linters don't like this sort of stuff.
|
|
||||||
Yet another reason not to use a markdown linter.
|
|
||||||
|
|
||||||
- And this is just the lame stupid old way to do this, as described by mardkownguide
|
|
||||||
|
|
||||||
> just indent your stuff and it works
|
|
||||||
> really it's as simple as that.
|
|
||||||
> bruh
|
|
||||||
|
|
||||||
there can be as many as infinite number of elements appended to the list that way.
|
|
||||||
|
|
||||||
you can even start a sublist here if you want to
|
|
||||||
|
|
||||||
- here's a new nested list
|
|
||||||
- could you imagine the potential
|
|
||||||
|
|
||||||
and here's an image of nothing
|
|
||||||
|
|
||||||
![image](https://example.com/nothing.png)
|
|
||||||
|
|
||||||
- I may also need to merge lists for this to work properly
|
|
||||||
|
|
||||||
### Third level header
|
|
||||||
|
|
||||||
text
|
|
||||||
|
|
||||||
#### 4th level text
|
|
||||||
|
|
||||||
- list
|
|
||||||
- > list with blockquote
|
|
||||||
> quote
|
|
||||||
> more of the same quote
|
|
||||||
>
|
|
||||||
> - inner list
|
|
||||||
> - list2
|
|
||||||
>
|
|
||||||
> ```plaintext
|
|
||||||
> code block inside a quote
|
|
||||||
> could you imagine that shit
|
|
||||||
> eh
|
|
||||||
> ```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
gnomo
|
|
||||||
|
|
||||||
indented preformatted text
|
|
||||||
indented preformatted text
|
|
||||||
function() peepeeopoopoo {
|
|
||||||
puts ass
|
|
||||||
}
|
|
||||||
indented preformatted text
|
|
Loading…
Reference in New Issue