func run()

in Sources/markdown-tool/Commands/FormatCommand.swift [191:245]


        func run() throws {
            var parseOptions = ParseOptions()
            if parseBlockDirectives {
                parseOptions.insert(.parseBlockDirectives)
            }
            if parseSymbolLinks {
                parseOptions.insert(.parseSymbolLinks)
            }
            let source: String
            let document: Document
            if let inputFilePath = inputFilePath {
                (source, document) = try MarkdownCommand.parseFile(at: inputFilePath, options: parseOptions)
            } else {
                (source, document) = try MarkdownCommand.parseStandardInput(options: parseOptions)
            }

            guard let emphasisMarker = MarkupFormatter.Options.EmphasisMarker(argument: emphasisMarker) else {
                throw ArgumentParser.ValidationError("The value '\(self.emphasisMarker)' is invalid for '--emphasis-marker'")
            }

            guard let unorderedListMarker = MarkupFormatter.Options.UnorderedListMarker(argument: unorderedListMarker) else {
                throw ArgumentParser.ValidationError("The value '\(self.emphasisMarker)' is invalid for '--unordered-list-marker'")
            }

            let orderedListNumerals: MarkupFormatter.Options.OrderedListNumerals
            switch orderedListCounting {
            case .allSame:
                orderedListNumerals = .allSame(orderedListStartNumeral)
            case .incrementing:
                orderedListNumerals = .incrementing(start: orderedListStartNumeral)
            }

            let preferredLineLimit = preferredMaximumLineLength.map {
                MarkupFormatter.Options.PreferredLineLimit(maxLength: $0.length, breakWith: lineSplittingElement)
            }

            let formatOptions = MarkupFormatter.Options(unorderedListMarker: unorderedListMarker,
                                                  orderedListNumerals: orderedListNumerals,
                                                  useCodeFence: useCodeFence,
                                                  defaultCodeBlockLanguage: defaultCodeBlockLanguage,
                                                  thematicBreakCharacter: thematicBreakCharacter,
                                                  thematicBreakLength: thematicBreakLength,
                                                  emphasisMarker: emphasisMarker,
                                                  condenseAutolinks: condenseAutolinks,
                                                  preferredHeadingStyle: preferredHeadingStyle,
                                                  preferredLineLimit: preferredLineLimit,
                                                  customLinePrefix: customLinePrefix)
            let formatted = document.format(options: formatOptions)
            print(formatted)
            if checkStructuralEquivalence {
                try checkStructuralEquivalence(between: document,
                                               and: Document(parsing: formatted, options: parseOptions),
                                               source: source)
            }
        }