純粋なSwiftUIコンポーネントを使用してマークダウンを表示します。 ViewBuilderの利点を取り、 TextとViewのカスタム外観を作成します。
import Parma
struct ContentView : View {
var markdown = " I'm **Strong**. "
var body : some View {
Parma ( markdown )
}
}その他の例については、デモアプリを参照してください。
Swift Package Managerは、Swiftコードの配布を管理するためのツールです。 Swiftビルドシステムと統合されて、すべてのプラットフォームの依存関係をダウンロード、コンパイル、リンクするプロセスを自動化します。
XcodeのGUIを使用してParma依存関係として追加すると、パッケージURLはhttps://github.com/dasautoooo/Parmaです。
Cocoapodsは、Cocoaプロジェクトの依存マネージャーです。使用法とインストール手順については、ウェブサイトをご覧ください。 Parmaココアポッドを使用してXcodeプロジェクトに統合するには、 Podfileで指定します。
pod 'Parma' TextスタイルをカスタマイズしてViewには、プロトコルParmaRenderableに準拠した新しいレンダリングを作成し、目的に合ったもののみを再実装します。最後に、 Parmaビューを作成するときにカスタマイズされたレンダリングを新しいレンダリングとして割り当てます。
import Parma
struct ContentView : View {
var markdown = " I'm **Strong**. "
var body : some View {
Parma ( markdown , render : MyRender ( ) )
}
}
struct MyRender : ParmaRenderable {
...
}これらの委任方法のいくつかを以下に変更したデモアップがあります。
/// Define the heading text style.
/// - Parameters:
/// - level: The level of heading.
/// - textView: The textView generated from captured heading string.
func heading ( level : HeadingLevel ? , textView : Text ) -> Text
/// Define the paragraph text style.
/// - Parameter text: The text string captured from paragraph.
func paragraph ( text : String ) -> Text
/// Define the text style for plain text. Do NOT recommend to alter this if there's no special purpose.
/// - Parameter text: The text string captured from markdown.
func plainText ( _ text : String ) -> Text
/// Define the strong text style.
/// - Parameter textView: The textView generated from captured strong string.
func strong ( textView : Text ) -> Text
/// Define the emphasis text style.
/// - Parameter textView: The textView generated from captured emphasis string.
func emphasis ( textView : Text ) -> Text
/// Define the link text style.
/// - Parameters:
/// - textView: The textView generated from captured link string.
/// - destination: The destination of the link.
func link ( textView : Text , destination : String ? ) -> Text
/// Define the code text style.
/// - Parameter text: The text string captured from code.
func code ( _ text : String ) -> Text
/// Define the style of heading view.
/// - Parameters:
/// - level: The level of heading.
/// - view: The view contains heading text.
func headingBlock ( level : HeadingLevel ? , view : AnyView ) -> AnyView
/// Define the style of paragraph view.
/// - Parameter view: The view contains view(s) which belong(s) to this paragraph.
func paragraphBlock ( view : AnyView ) -> AnyView
/// Define the style of list item.
/// - Parameter attributes: Attributes of the list containing the item. Those must be considered for proper item rendering.
/// - Parameter index: Normalized index of the list item. For exemple, the index of the third item of a one level list would be `[2]` and the second item of a sublist appearing fourth in it's parent list would be `[3, 1]`.
/// - Parameter view: The view contains view(s) which belong(s) to this item.
func listItem ( attributes : ListAttributes , index : [ Int ] , view : AnyView ) -> AnyView
/// Define the style of image view.
/// - Parameter urlString: The url string for this image view.
/// - Parameter altTextView: The view contains alt text.
func imageView ( with urlString : String , altTextView : AnyView ? ) -> AnyView パルマは北イタリアの都市であり、建築、音楽、芸術で有名です。この都市名をプロジェクト名として選択する理由は、この街での生涯の生活と働きを最も過ごした有名なタイポグラファーであるGiambattista Bodoniです。
ボドーニは、パルマのタイプデザイナーであるイタリアのタイポグラファーでした。彼の寿命の間、彼は最近ボドーニとして知られている多くの書体を設計しました。各MacにはBodoniフォントがインストールされており、無料で使用できます。
パッケージはダウン上に構築されており、SwiftのMarkdownパーサーです。