mdx-tex 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9411cc54322085d04d1e79066d6b4e421471eb06ee4a22d1adcd1e554237651c
4
+ data.tar.gz: 1df7a230b6ffd485f8a26c87ce0fd8a07132d37070547d1139c58b99fb1c6f44
5
+ SHA512:
6
+ metadata.gz: ed03863a04481d90f8a7d9836ab5aaf6b1dac1fa0451b9d5b2b8a4db713a2441e57035438f848fafe6b4df1440ea4be8b5ced84c0495e38d18c2cd0b97366fe1
7
+ data.tar.gz: 85e84e1aa15bb86c0f95bfc37aefd1948e23795044cd0851822ac9fb0a7e2e733962b8c9ef0af230cf9841e609c4ad297a4f1bc0f764ebd9e0f81c4a6cfd0f10
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gloria Budiman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MarkLeft
4
+ # Holds global defaults for all MarkLeft conversions.
5
+ # Override these in an initializer (e.g. config/initializers/mark_left.rb):
6
+ #
7
+ # MarkLeft.configure do |config|
8
+ # config.header_level = 'h2' # Textile heading tag (default: 'h3')
9
+ # config.list_depth = 1 # Leading asterisks for depth-1 unordered list items (default: 3)
10
+ # end
11
+ #
12
+ # Per-call options always take precedence over these defaults:
13
+ #
14
+ # MarkLeft.convert(markdown, list_depth: 1)
15
+ class Configuration
16
+ attr_reader :header_level, :list_depth
17
+
18
+ def initialize
19
+ @header_level = 'h3'
20
+ @list_depth = 3
21
+ end
22
+
23
+ def header_level=(value)
24
+ Markdown::ToTextile::InvalidHeaderLevelError.validate!(value)
25
+ @header_level = value
26
+ end
27
+
28
+ def list_depth=(value)
29
+ Markdown::ToTextile::InvalidListDepthError.validate!(value)
30
+ @list_depth = value
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MarkLeft
4
+ VERSION = '0.1.0'
5
+ end
data/lib/mark_left.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mark_left/version'
4
+ require 'mark_left/configuration'
5
+ require 'markdown/to_textile'
6
+
7
+ module MarkLeft
8
+ class << self
9
+ attr_writer :configuration
10
+
11
+ def configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
15
+ def configure
16
+ yield configuration
17
+ end
18
+
19
+ def convert(markdown, **options)
20
+ merged = { header_level: configuration.header_level, list_depth: configuration.list_depth }.merge(options)
21
+ Markdown::ToTextile.new(**merged).convert(markdown)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Markdown
4
+ class ToTextile
5
+ # Converts Markdown bold syntax to Textile bold syntax.
6
+ # Both ** and __ delimiters are supported and processed independently.
7
+ # Note: nested mixed delimiters (e.g. __**text**__) are not supported.
8
+ #
9
+ # | Input (Markdown) | Output (Textile) |
10
+ # |---------------------------|-------------------------|
11
+ # | **hello** | *hello* |
12
+ # | __hello__ | *hello* |
13
+ # | foo **bar** baz | foo *bar* baz |
14
+ # | **a** and **b** | *a* and *b* |
15
+ # | **a** and __b__ | *a* and *b* |
16
+ module Bold
17
+ def self.execute(line)
18
+ line
19
+ .gsub(/\*\*(.+?)\*\*/, '*\1*')
20
+ .gsub(/__(.+?)__/, '*\1*')
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Markdown
4
+ class ToTextile
5
+ # Converts a Markdown heading to a Textile heading.
6
+ # The caller supplies the desired Textile header tag via +header_level+.
7
+ # A space must follow the # characters for the line to be recognised as a heading.
8
+ # Lines that do not match are returned unchanged.
9
+ #
10
+ # | Input (Markdown) | header_level | Output (Textile) |
11
+ # |--------------------|--------------|------------------|
12
+ # | # Title | h1 | h1. Title |
13
+ # | ## Section | h2 | h2. Section |
14
+ # | ### Note | h3 | h3. Note |
15
+ # | #NoSpace | h1 | #NoSpace |
16
+ module Header
17
+ def self.execute(line, header_level:)
18
+ line.sub(/\A#+\s+(.+)\z/, "#{header_level}. \\1")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Markdown
4
+ class ToTextile
5
+ # Converts a Markdown ordered list item to a Textile ordered list item.
6
+ # Nesting depth is determined by leading indentation (2 spaces per level).
7
+ # Odd-numbered spaces are rounded down: 1 space is treated the same as 0 spaces.
8
+ #
9
+ # | Input (Markdown) | Output (Textile) |
10
+ # |---------------------|------------------|
11
+ # | 1. Item | # Item |
12
+ # | 99. Item | # Item |
13
+ # | 1. Nested | ## Nested |
14
+ # | 1. Deep | ### Deep |
15
+ module OrderedList
16
+ INDENT_SIZE = 2
17
+
18
+ def self.execute(line)
19
+ line.sub(/\A(\s*)\d+\.\s+(.+)\z/) do
20
+ depth = (::Regexp.last_match(1).length / INDENT_SIZE) + 1
21
+ "#{'#' * depth} #{::Regexp.last_match(2)}"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Markdown
4
+ class ToTextile
5
+ # Converts a Markdown unordered list item to a Textile unordered list item.
6
+ # Nesting depth is determined by leading indentation (2 spaces per level),
7
+ # offset by +list_depth+ (default: 3).
8
+ # Odd-numbered spaces are rounded down: 1 space is treated the same as 0 spaces.
9
+ #
10
+ # | Input (Markdown) | list_depth | Output (Textile) |
11
+ # |---------------------|------------|------------------|
12
+ # | - Item | 3 | *** Item |
13
+ # | - Nested | 3 | **** Nested |
14
+ # | - Item | 1 | * Item |
15
+ # | - Nested | 1 | ** Nested |
16
+ module UnorderedList
17
+ INDENT_SIZE = 2
18
+
19
+ def self.execute(line, list_depth: 3)
20
+ line.sub(/\A(\s*)-\s+(.+)\z/) do
21
+ depth = (::Regexp.last_match(1).length / INDENT_SIZE) + list_depth
22
+ "#{'*' * depth} #{::Regexp.last_match(2)}"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'markdown/to_textile/header'
4
+ require 'markdown/to_textile/bold'
5
+ require 'markdown/to_textile/unordered_list'
6
+ require 'markdown/to_textile/ordered_list'
7
+
8
+ module Markdown
9
+ class ToTextile
10
+ VALID_HEADER_LEVELS = %w[h1 h2 h3 h4 h5 h6].freeze
11
+
12
+ class InvalidListDepthError < ArgumentError
13
+ def initialize(value)
14
+ super("list_depth must be a positive integer, got: #{value.inspect}")
15
+ end
16
+
17
+ def self.validate!(value)
18
+ raise self, value unless value.is_a?(Integer) && value.positive?
19
+ end
20
+ end
21
+
22
+ class InvalidHeaderLevelError < ArgumentError
23
+ def initialize(value)
24
+ super("header_level must be one of #{VALID_HEADER_LEVELS.join(', ')}, got: #{value.inspect}")
25
+ end
26
+
27
+ def self.validate!(value)
28
+ raise self, value unless VALID_HEADER_LEVELS.include?(value)
29
+ end
30
+ end
31
+
32
+ def initialize(header_level: 'h3', list_depth: 3)
33
+ InvalidHeaderLevelError.validate!(header_level)
34
+ InvalidListDepthError.validate!(list_depth)
35
+
36
+ @header_level = header_level
37
+ @list_depth = list_depth
38
+ end
39
+
40
+ def convert(input)
41
+ return '' if input.nil?
42
+
43
+ input.to_s.split("\n", -1).map { |line| convert_line(line) }.join("\n")
44
+ end
45
+
46
+ private
47
+
48
+ def convert_line(line)
49
+ line = Header.execute(line, header_level: @header_level)
50
+ line = Bold.execute(line)
51
+ line = UnorderedList.execute(line, list_depth: @list_depth)
52
+ OrderedList.execute(line)
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mdx-tex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gloria Budiman
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Converts Markdown syntax to Textile syntax, with configurable header
13
+ levels and list depth.
14
+ email:
15
+ - wahyu.g@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE
21
+ - lib/mark_left.rb
22
+ - lib/mark_left/configuration.rb
23
+ - lib/mark_left/version.rb
24
+ - lib/markdown/to_textile.rb
25
+ - lib/markdown/to_textile/bold.rb
26
+ - lib/markdown/to_textile/header.rb
27
+ - lib/markdown/to_textile/ordered_list.rb
28
+ - lib/markdown/to_textile/unordered_list.rb
29
+ homepage: https://github.com/gbudiman/mark-left
30
+ licenses:
31
+ - MIT
32
+ metadata:
33
+ rubygems_mfa_required: 'true'
34
+ homepage_uri: https://github.com/gbudiman/mark-left
35
+ source_code_uri: https://github.com/gbudiman/mark-left
36
+ changelog_uri: https://github.com/gbudiman/mark-left/blob/main/CHANGELOG.md
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '2.6'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 4.0.3
52
+ specification_version: 4
53
+ summary: Convert between Markdown and Textile
54
+ test_files: []