Skip to content

jds691/SwiftBbML

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftBbML

Swift parser for Anthology's Blackboard Markup Language (BbML).

This package includes a V1 compliant parser (with some known limitations) which converts BbML elements into "chunks". Each chunk represents a different type of content that would logically need to be handled differetly by a client application. The current list is:

  • text
  • image
  • document
  • video
  • math

In the future I will hopefully implement a parser that can convert chunks back into valid BbML.

Usage

To include SwiftBbML in your project, you'll need to include it as a dependency in your Package.swift file:

dependencies: [
    .package(url: "https://github.com/jds691/SwiftBbML.git", from: "1.0.0"),
]

To begin using it in your project, create an instance of BbMLParser and call the parse(_: String) method to receive a list of chunks back out for rendering:

import Foundation
import SwiftBbML

@main
struct BbMLExample {
    static func main() {
        let bbML = "<div><h4>BbML Document</h4><p>Hello, World!</p></div>"
        let parser = BbMLParser()

        do {
            let chunks = try parser.parse(bbML)

            // BbMLContent conforms to Collection
            for chunk in chunks {
                switch chunk {
                    case .text(let attributedString):
                        print(String(attributedString.characters))

                    // Handle the other cases appropriately too...
                    case .image(url: let url, altDescription: let altDescription, renderMode: let renderMode):
                        break
                    case .document(url: let url, attachmentInfo: let attachmentInfo):
                        break
                    case .math(_):
                        break
                    case .video(url: let url):
                        break
                }
            }
        } catch {
            // Handles errors appropriately...
        }
    }
}

// Output:
//
// BbML Document
// Hello, World!

Important

If you are using SwiftBbML in a SwiftUI application, you should configure the parser so it can make SwiftUI specific changes:

let config = BbMLParser.ParserOptions(appUsesSwiftUI: true)
let parser = BbMLParser(options: config)

Known Limitations

  • All CSS styles (excluding text-decoration: underline;) are ignored during parsing, which can lead to documents not looking 1:1 to a Blackboard Learn environment.
    • However any styles that would normally implicitly be handled by the user agent are correctly handled e.g. h4-6 are sized correctly, em is correctly italicised, strong is correctly bolded.
  • Lists do not render correctly when using SwiftUI.
  • The "LTI Content Market" plugin is not supported, despite being documented.
  • The "Video Everywhere (aka Collab Integration; aka Collab Video; aka Video Integration)" plugin is not supported, despite being documented.

About

Swift parser for Anthology's Blackboard Markup Language (BbML).

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages