Skip to content

Commit

Permalink
Fix SwiftMarkdown naming
Browse files Browse the repository at this point in the history
Summary: Renamed our internal import of SwiftMarkdown to correctly use the module name `Markdown` rather than `SwiftMarkdown`. This is required to match open source.

Differential Revision: D51562372

fbshipit-source-id: 8cbf511c0bf6ba5f4a19ab6110529854b7a8937f
  • Loading branch information
Amy Worrall authored and facebook-github-bot committed Nov 24, 2023
1 parent cdb0194 commit a015cf1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ let package = Package(
"Lexical",
"LexicalLinkPlugin",
"LexicalListPlugin",
.product(name: "SwiftMarkdown", package: "swift-markdown")
.product(name: "Markdown", package: "swift-markdown")
],
path: "./Plugins/LexicalMarkdown/LexicalMarkdown"),
.testTarget(
name: "LexicalMarkdownTests",
dependencies: [
"Lexical",
"LexicalMarkdown",
.product(name: "SwiftMarkdown", package: "swift-markdown"),
.product(name: "Markdown", package: "swift-markdown"),
],
path: "./Plugins/LexicalMarkdown/LexicalMarkdownTests"),
]
Expand Down
4 changes: 2 additions & 2 deletions Plugins/LexicalMarkdown/LexicalMarkdown/LexicalMarkdown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation
import Lexical
import SwiftMarkdown
import Markdown

open class LexicalMarkdown: Plugin {
public init() {}
Expand All @@ -27,6 +27,6 @@ open class LexicalMarkdown: Plugin {
return ""
}

return SwiftMarkdown.Document(root.getChildren().exportAsBlockMarkdown()).format()
return Markdown.Document(root.getChildren().exportAsBlockMarkdown()).format()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,54 @@ import Foundation
import Lexical
import LexicalLinkPlugin
import LexicalListPlugin
import SwiftMarkdown
import Markdown

private func makeIndentation(_ count: Int) -> String {
String(repeating: "\u{009}", count: count)
}

public protocol NodeMarkdownBlockSupport: Lexical.Node {
func exportBlockMarkdown() throws -> SwiftMarkdown.BlockMarkup
func exportBlockMarkdown() throws -> Markdown.BlockMarkup
}

public protocol NodeMarkdownInlineSupport: Lexical.Node {
func exportInlineMarkdown(indentation: Int) throws -> SwiftMarkdown.InlineMarkup
func exportInlineMarkdown(indentation: Int) throws -> Markdown.InlineMarkup
}

extension Lexical.ParagraphNode: NodeMarkdownBlockSupport {
public func exportBlockMarkdown() throws -> SwiftMarkdown.BlockMarkup {
return SwiftMarkdown.Paragraph(getChildren().exportAsInlineMarkdown(indentation: getIndent()))
public func exportBlockMarkdown() throws -> Markdown.BlockMarkup {
return Markdown.Paragraph(getChildren().exportAsInlineMarkdown(indentation: getIndent()))
}
}

extension Lexical.TextNode: NodeMarkdownInlineSupport {
public func exportInlineMarkdown(indentation: Int) throws -> SwiftMarkdown.InlineMarkup {
public func exportInlineMarkdown(indentation: Int) throws -> Markdown.InlineMarkup {
let format = getFormat()
var node: SwiftMarkdown.InlineMarkup = SwiftMarkdown.Text(makeIndentation(indentation) + getTextPart())
var node: Markdown.InlineMarkup = Markdown.Text(makeIndentation(indentation) + getTextPart())

if format.code {
// NOTE (mani) - code must always come first
node = SwiftMarkdown.InlineCode(makeIndentation(indentation) + getTextPart())
node = Markdown.InlineCode(makeIndentation(indentation) + getTextPart())
}

if format.bold {
node = SwiftMarkdown.Strong(node)
node = Markdown.Strong(node)
}

if format.strikethrough {
node = SwiftMarkdown.Strikethrough(node)
node = Markdown.Strikethrough(node)
}

if format.italic {
// TODO (mani) - underline + italic both use Emphasis node
// should we create a separate node?
node = SwiftMarkdown.Emphasis(node)
node = Markdown.Emphasis(node)
}

if format.underline {
// TODO (mani) - underline + italic both use Emphasis node
// should we create a separate node?
node = SwiftMarkdown.Emphasis(node)
node = Markdown.Emphasis(node)
}

if format.superScript {
Expand All @@ -79,17 +79,17 @@ extension LexicalListPlugin.ListNode: NodeMarkdownBlockSupport {
// incorrect markdown. Assume indentations are not properly supported.
// Also, no support for checkmarks in Lexical AFAIK.

public func exportBlockMarkdown() throws -> SwiftMarkdown.BlockMarkup {
public func exportBlockMarkdown() throws -> Markdown.BlockMarkup {
let children = getChildren().exportAsBlockMarkdown()
.compactMap { $0 as? SwiftMarkdown.ListItem }
.compactMap { $0 as? Markdown.ListItem }
switch getListType() {
case .bullet:
return SwiftMarkdown.UnorderedList(children)
return Markdown.UnorderedList(children)
case .check:
// TODO (mani) - how does lexical mark a checked item?
return SwiftMarkdown.UnorderedList(children)
return Markdown.UnorderedList(children)
case .number:
var list = SwiftMarkdown.OrderedList(children)
var list = Markdown.OrderedList(children)
let start = getStart()
if start > 0 {
list.startIndex = UInt(start)
Expand All @@ -100,62 +100,62 @@ extension LexicalListPlugin.ListNode: NodeMarkdownBlockSupport {
}

extension LexicalListPlugin.ListItemNode: NodeMarkdownBlockSupport {
public func exportBlockMarkdown() throws -> SwiftMarkdown.BlockMarkup {
let children: [SwiftMarkdown.BlockMarkup] = getChildren().compactMap {
public func exportBlockMarkdown() throws -> Markdown.BlockMarkup {
let children: [Markdown.BlockMarkup] = getChildren().compactMap {
if let inline = try? ($0 as? NodeMarkdownInlineSupport)?.exportInlineMarkdown(indentation: getIndent()) {
return SwiftMarkdown.Paragraph(inline)
return Markdown.Paragraph(inline)
} else {
return try? ($0 as? NodeMarkdownBlockSupport)?.exportBlockMarkdown()
}
}

if let parent = getParent() as? ListNode, parent.getListType() == .check {
// TODO (mani) - how does lexical mark a checked item?
return SwiftMarkdown.ListItem(checkbox: nil, children)
return Markdown.ListItem(checkbox: nil, children)
} else {
return SwiftMarkdown.ListItem(children)
return Markdown.ListItem(children)
}
}
}

extension LexicalLinkPlugin.LinkNode: NodeMarkdownInlineSupport {
public func exportInlineMarkdown(indentation: Int) throws -> SwiftMarkdown.InlineMarkup {
SwiftMarkdown.Link(destination: getURL(),
public func exportInlineMarkdown(indentation: Int) throws -> Markdown.InlineMarkup {
Markdown.Link(destination: getURL(),
getChildren()
.exportAsInlineMarkdown(indentation: getIndent())
.compactMap { $0 as? SwiftMarkdown.RecurringInlineMarkup })
.compactMap { $0 as? Markdown.RecurringInlineMarkup })
}
}

extension Lexical.CodeNode: NodeMarkdownBlockSupport {
public func exportBlockMarkdown() throws -> SwiftMarkdown.BlockMarkup {
public func exportBlockMarkdown() throws -> Markdown.BlockMarkup {
// TODO (mani) - do code blocks have formatting?
// TODO (mani) - indentation for codeblocks?
SwiftMarkdown.CodeBlock(getTextContent())
Markdown.CodeBlock(getTextContent())
}
}

extension Lexical.LineBreakNode: NodeMarkdownInlineSupport {
public func exportInlineMarkdown(indentation: Int) throws -> SwiftMarkdown.InlineMarkup {
SwiftMarkdown.LineBreak()
public func exportInlineMarkdown(indentation: Int) throws -> Markdown.InlineMarkup {
Markdown.LineBreak()
}
}

extension Lexical.QuoteNode: NodeMarkdownBlockSupport {
public func exportBlockMarkdown() throws -> SwiftMarkdown.BlockMarkup {
SwiftMarkdown.BlockQuote(
public func exportBlockMarkdown() throws -> Markdown.BlockMarkup {
Markdown.BlockQuote(
getChildren()
.exportAsInlineMarkdown(indentation: getIndent())
.map {
SwiftMarkdown.Paragraph($0)
Markdown.Paragraph($0)
}
)
}
}

extension Lexical.HeadingNode: NodeMarkdownBlockSupport {
public func exportBlockMarkdown() throws -> SwiftMarkdown.BlockMarkup {
SwiftMarkdown.Heading(
public func exportBlockMarkdown() throws -> Markdown.BlockMarkup {
Markdown.Heading(
level: getTag().intValue,
getChildren().exportAsInlineMarkdown(indentation: getIndent())
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

import Foundation
import Lexical
import SwiftMarkdown
import Markdown

extension Array where Element == Node {
func exportAsInlineMarkdown(indentation: Int) -> [SwiftMarkdown.InlineMarkup] {
func exportAsInlineMarkdown(indentation: Int) -> [Markdown.InlineMarkup] {
compactMap {
try? ($0 as? NodeMarkdownInlineSupport)?.exportInlineMarkdown(indentation: indentation)
}
}

func exportAsBlockMarkdown() -> [SwiftMarkdown.BlockMarkup] {
func exportAsBlockMarkdown() -> [Markdown.BlockMarkup] {
compactMap {
try? ($0 as? NodeMarkdownBlockSupport)?.exportBlockMarkdown()
}
Expand Down

0 comments on commit a015cf1

Please sign in to comment.