Converts Markdown (MDX) to Textile, for those of you unfortunate enough to have to maintain a legacy system that relies on Textile.
Pure Ruby, no runtime dependencies.
Note: Currently only supports MDX -> Textile conversion. Textile -> MDX conversion is on the roadmap.
Add to your Gemfile:
gem 'mdx-tex'bundle installOr install directly:
gem install mdx-texrequire 'mdx_tex'
MdxTex.to_textile(markdown: '# Hello **world**')
# => "h3. Hello *world*"
# Override options per call
MdxTex.to_textile(markdown: '# Hello', header_level: 'h1')
# => "h1. Hello"
# Or set them globally
MdxTex.configure do |config|
config.header_level = 'h2'
config.list_depth = 1
end
# Per-call options take precedence over global config
MdxTex.to_textile(markdown: '- item', list_depth: 2)Adds to_textile directly to String. Off by default.
Any Ruby app:
require 'mdx_tex/core_ext/string'
'# Hello **world**'.to_textile
# => "h3. Hello *world*"
'- item'.to_textile(list_depth: 1)
# => "* item"Or load it through config:
MdxTex.configure do |config|
config.enable_string_extension = true
end
MdxTex.load_string_extension!Rails (config/initializers/mdx_tex.rb):
MdxTex.configure do |config|
config.enable_string_extension = true
endThe Railtie loads this automatically after initialization.
Converts all Markdown headings (# through ######) to the same Textile heading tag. The number of # doesn't matter. header_level controls which tag to use (default: h3).
| Markdown | header_level | Textile |
|---|---|---|
# Title |
h3 (default) |
h3. Title |
## Title |
h3 (default) |
h3. Title |
###### Title |
h3 (default) |
h3. Title |
# Title |
h1 |
h1. Title |
### Title |
h1 |
h1. Title |
Requires a space after #. #NoSpace won't convert.
This does not preserve heading hierarchy yet (## and ### both produce the same tag). We plan to fix this in a future version.
**text** and __text__ become *text*. Multiple spans and mixed delimiters work on the same line.
| Markdown | Textile |
|---|---|
**hello** |
*hello* |
__hello__ |
*hello* |
**a** and **b** |
*a* and *b* |
**a** and __b__ |
*a* and *b* |
- item becomes Textile * item. Nesting uses 2-space indentation. list_depth controls the base asterisk count (default: 3).
| Markdown | list_depth | Textile |
|---|---|---|
- Item |
1 | * Item |
- Item |
3 | *** Item |
- Nested |
3 | **** Nested |
- Deep |
3 | ***** Deep |
1. item becomes # item. Ignores the actual number. Nesting uses 2-space indentation.
| Markdown | Textile |
|---|---|
1. First |
# First |
99. Any number |
# Any number |
1. Nested |
## Nested |
1. Deep |
### Deep |
The following Markdown syntax passes through as-is (no conversion):
- Italic (
*text*,_text_) - Strikethrough (
~~text~~) - Links (
[text](url)) - Images (
) - Inline code (
`code`) - Code blocks (
```) - Blockquotes (
>) - Tables
- Horizontal rules (
---) - Task lists (
- [ ],- [x])
| Option | Type | Valid Values | Default | Description |
|---|---|---|---|---|
header_level |
String | h1..h6 |
h3 |
Textile heading tag |
list_depth |
Integer | Positive integer | 3 |
Base asterisk count for unordered lists |
Bad values raise InvalidHeaderLevelError or InvalidListDepthError.
Input:
# **Title**
- item one
- **item two**
- nested with **bold**
1. **first**
1. secondOutput (default config):
h3. *Title*
*** item one
*** *item two*
**** nested with *bold*
# *first*
# second
git clone https://github.com/gbudiman/mdx-tex.git
cd mdx-tex
bundle installUses overcommit for pre-commit RuboCop. After cloning:
bundle exec overcommit --install
bundle exec overcommit --signbundle exec rspecbundle exec rubocopbin/release patch # 0.1.10 → 0.1.11
bin/release minor # 0.1.10 → 0.2.0
bin/release major # 0.1.10 → 1.0.0Runs specs, bumps the version, commits, tags, and pushes. GitHub Actions handles the RubyGems publish.
MIT