forked from metanorma/coradoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inline classes, #to_adoc, consistency renames
- metanorma#31 added classes for inline elements - metanorma#10 added #to_adoc to Coradoc::Document classes based upon reverse_adoc code - renamed numbered/unnumbered to ordered/unordered for consistency with metanorma/asciidoc
- Loading branch information
Showing
34 changed files
with
490 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Coradoc | ||
module Document | ||
class Audio | ||
attr_reader :id, :title, :src, :options | ||
|
||
def initialize(title, options = {}) | ||
@title = title | ||
@id = options.fetch(:id, nil) | ||
@src = options.fetch(:src, '') | ||
@options = options.fetch(:options, []) | ||
end | ||
|
||
def to_adoc | ||
anchor = @id ? "[[#{@id}]]\n" : "" | ||
title = ".#{@title}\n" unless @title.empty? | ||
|
||
opts = "" | ||
if @options.any? | ||
opts = %{options="#{@options.join(',')}"} | ||
end | ||
|
||
[anchor, title, "audio::", @src, "[", opts, "]"].join("") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Coradoc | ||
module Document | ||
module Break | ||
class ThematicBreak | ||
def to_adoc | ||
"\n* * *\n" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "coradoc/document/inline/anchor" | ||
require "coradoc/document/inline/bold" | ||
require "coradoc/document/inline/hard_line_break" | ||
require "coradoc/document/inline/highlight" | ||
require "coradoc/document/inline/image" | ||
require "coradoc/document/inline/italic" | ||
require "coradoc/document/inline/monospace" | ||
require "coradoc/document/inline/quotation" | ||
require "coradoc/document/inline/subscript" | ||
require "coradoc/document/inline/superscript" | ||
|
||
module Coradoc | ||
module Document | ||
module Inline | ||
class << self | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Coradoc | ||
module Document | ||
module Inline | ||
class Anchor | ||
attr_reader :id, :href, :title, :name | ||
|
||
def initialize(options = {}) | ||
@id = options.fetch(:id,nil) | ||
@href = options.fetch(:href,nil) | ||
@title = options.fetch(:title, nil) | ||
@name = options.fetch(:name,nil) | ||
end | ||
|
||
def to_adoc | ||
if /^_Toc\d+$|^_GoBack$/.match @id | ||
"" | ||
elsif !@id.nil? && !@id.empty? | ||
"[[#{@id}]]" | ||
elsif @href.to_s.start_with?('#') | ||
@href = @href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_") | ||
if @name.to_s.empty? | ||
"<<#{@href}>>" | ||
else | ||
"<<#{@href},#{@name}>>" | ||
end | ||
elsif @href.to_s.empty? | ||
@name | ||
else | ||
@name = @title if @name.to_s.empty? | ||
@href = "link:#{@href}" unless @href.to_s =~ URI::DEFAULT_PARSER.make_regexp | ||
link = "#{@href}[#{@name}]" | ||
link.prepend(' ') | ||
link | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Coradoc | ||
module Document | ||
module Inline | ||
class Bold | ||
attr_accessor :content | ||
def initialize(content) | ||
@content = content | ||
end | ||
def to_adoc | ||
content = Coradoc::Generator.gen_adoc(@content) | ||
"#{content[/^\s*/]}*#{content.strip}*#{content[/\s*$/]}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Coradoc | ||
module Document | ||
module Inline | ||
class HardLineBreak | ||
def to_adoc | ||
" +\n" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Coradoc | ||
module Document | ||
module Inline | ||
class Highlight | ||
attr_accessor :content | ||
def initialize(content) | ||
@content = content | ||
end | ||
def to_adoc | ||
content = Coradoc::Generator.gen_adoc(@content) | ||
"#{content[/^\s*/]}##{content.strip}##{content[/\s*$/]}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Coradoc | ||
module Document | ||
module Inline | ||
class Image | ||
attr_reader :id, :title, :src, :alt, :width, :height | ||
def initialize(options = ()) | ||
@id = options.fetch(:id, nil) | ||
@title = options.fetch(:title, nil) | ||
@src = options.fetch(:src, nil) | ||
@alt = options.fetch(:alt, nil) | ||
@width = options.fetch(:width, nil) | ||
@height = options.fetch(:height, nil) | ||
end | ||
def to_adoc | ||
anchor = @id ? "[[#{@id}]]\n" : "" | ||
title = ".#{@title}\n" unless @title.empty? | ||
attrs = @alt | ||
attrs = "\"\"" if (@width || @height) && @alt.nil? | ||
attrs += ",#{@width}" if @width | ||
attrs += ",#{@height}" if @width && @height | ||
[anchor, title, "image::", src, "[", attrs, "]"].join("") | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Coradoc | ||
module Document | ||
module Inline | ||
class Italic | ||
attr_accessor :content | ||
def initialize(content) | ||
@content = content | ||
end | ||
def to_adoc | ||
content = Coradoc::Generator.gen_adoc(@content) | ||
"#{content[/^\s*/]}_#{content.strip}_#{content[/\s*$/]}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Coradoc | ||
module Document | ||
module Inline | ||
class Monospace | ||
attr_accessor :content | ||
def initialize(content) | ||
@content = content | ||
end | ||
def to_adoc | ||
content = Coradoc::Generator.gen_adoc(@content) | ||
"`#{content}`" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Coradoc | ||
module Document | ||
module Inline | ||
class Quotation | ||
attr_accessor :content | ||
def initialize(content) | ||
@content = content | ||
end | ||
def to_adoc | ||
content = Coradoc::Generator.gen_adoc(@content) | ||
"#{content[/^\s*/]}\"#{content.strip}\"#{content[/\s*$/]}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Coradoc | ||
module Document | ||
module Inline | ||
class Subscript | ||
attr_accessor :content | ||
def initialize(content) | ||
@content = content | ||
end | ||
|
||
def to_adoc | ||
content = Coradoc::Generator.gen_adoc(@content) | ||
"#{content[/^\s*/]}~#{content.strip}~#{content[/\s*$/]}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Coradoc | ||
module Document | ||
module Inline | ||
class Superscript | ||
attr_accessor :content | ||
def initialize(content) | ||
@content = content | ||
end | ||
def to_adoc | ||
content = Coradoc::Generator.gen_adoc(@content) | ||
"#{content[/^\s*/]}^#{content.strip}^#{content[/\s*$/]}" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.