Skip to content

Commit

Permalink
Revert "Move Markdown to inside the compiler. (#8115)"
Browse files Browse the repository at this point in the history
This reverts commit 491f26b.
  • Loading branch information
asterite authored and bcardiff committed Sep 10, 2019
1 parent 4a0dc6b commit 719da1b
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 50 deletions.
@@ -1,13 +1,13 @@
require "spec"
require "../../../../../src/compiler/crystal/tools/doc/markdown"
require "markdown"

private def assert_render(input, output, file = __FILE__, line = __LINE__)
it "renders #{input.inspect}", file, line do
Crystal::Doc::Markdown.to_html(input).should eq(output), file, line
Markdown.to_html(input).should eq(output), file, line
end
end

describe Crystal::Doc::Markdown do
describe Markdown do
assert_render "", ""
assert_render "Hello", "<p>Hello</p>"
assert_render "Hello\nWorld", "<p>Hello\nWorld</p>"
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/tools/doc/generator.cr
Expand Up @@ -303,7 +303,7 @@ class Crystal::Doc::Generator
string = isolate_flag_lines string
string += build_flag_lines_from_annotations context
markdown = String.build do |io|
Markdown.parse string, Markdown::DocRenderer.new(context, io)
Markdown.parse string, MarkdownDocRenderer.new(context, io)
end
generate_flags markdown
end
Expand Down
36 changes: 0 additions & 36 deletions src/compiler/crystal/tools/doc/markdown/markdown.cr

This file was deleted.

@@ -1,13 +1,11 @@
require "./*"
require "markdown"

class Crystal::Doc::Markdown::DocRenderer < Crystal::Doc::Markdown::HTMLRenderer
class Crystal::Doc::MarkdownDocRenderer < Markdown::HTMLRenderer
def self.new(obj : Constant | Macro | Method, io)
new obj.type, io
end

@type : Crystal::Doc::Type

def initialize(@type : Crystal::Doc::Type, io)
def initialize(@type : Type, io)
super(io)

@inside_inline_code = false
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/tools/playground/server.cr
@@ -1,8 +1,8 @@
require "http/server"
require "logger"
require "ecr/macros"
require "markdown"
require "compiler/crystal/tools/formatter"
require "compiler/crystal/tools/doc/markdown"

module Crystal::Playground
class Session
Expand Down Expand Up @@ -247,7 +247,7 @@ module Crystal::Playground
end

if extname == ".md" || extname == ".cr"
content = Crystal::Doc::Markdown.to_html(content)
content = Markdown.to_html(content)
end
content
rescue e
Expand Down
1 change: 1 addition & 0 deletions src/docs_main.cr
Expand Up @@ -19,6 +19,7 @@ require "./llvm"
require "./logger"
require "./macros"
require "./math/**"
require "./markdown"
require "./oauth"
require "./oauth2"
require "./openssl"
Expand Down
29 changes: 29 additions & 0 deletions src/markdown.cr
@@ -0,0 +1,29 @@
# Markdown library parses Markdown text. It supports rendering to HTML text.
#
# Usage:
#
# ```
# require "markdown"
#
# text = "## This is title \n This is a [link](http://crystal-lang.org)"
#
# Markdown.to_html(text)
# # => <h2>This is title</h2>
# # => <p>This is a <a href="http://crystal-lang.org">link</a></p>
# ```
#
# NOTE: This library is in its early stage. Many features are still in development.
class Markdown
def self.parse(text, renderer)
parser = Parser.new(text, renderer)
parser.parse
end

def self.to_html(text) : String
String.build do |io|
parse text, Markdown::HTMLRenderer.new(io)
end
end
end

require "./markdown/*"
@@ -1,6 +1,6 @@
require "./renderer"

class Crystal::Doc::Markdown::HTMLRenderer
class Markdown::HTMLRenderer
include Renderer

def initialize(@io : IO)
Expand Down
@@ -1,4 +1,4 @@
class Crystal::Doc::Markdown::Parser
class Markdown::Parser
record PrefixHeader, count : Int32
record UnorderedList, char : Char
record CodeFence, language : String
Expand Down
@@ -1,4 +1,4 @@
module Crystal::Doc::Markdown::Renderer
module Markdown::Renderer
abstract def begin_paragraph
abstract def end_paragraph
abstract def begin_italic
Expand Down

0 comments on commit 719da1b

Please sign in to comment.