GithubHelp home page GithubHelp logo

tophat / richtextview Goto Github PK

View Code? Open in Web Editor NEW
1.2K 23.0 75.0 3.11 MB

iOS Text View (UIView) that Properly Displays LaTeX, HTML, Markdown, and YouTube/Vimeo Links

Home Page: https://richtextview.com

License: Apache License 2.0

Ruby 4.22% Swift 91.33% Objective-C 0.42% JavaScript 2.76% CSS 0.87% HTML 0.42%
richtextview ios-swift opensource latex html markdown youtube vimeo

richtextview's Introduction


⚠️ This project is deprecated (2023-04-18) ⚠️

Unfortunately, we were unable to find external contributors. Feel free to fork this project. If a fork takes off, message us on our Discord and we can look at adding a link to the new project in this README.

RichTextView

Cocoapods Carthage compatible Builds
All Contributors Discord License - Apache-2 Maturity badge - level 3 Pull Reminders

iOS Text View (UIView) that Properly Displays LaTeX, HTML, Markdown, and YouTube/Vimeo Links

Installation

Using Cocoapods

Simply add the following to your Podfile:

pod 'RichTextView'

And run pod install in your repo.

Using Carthage

Simply add the following to your Cartfile:

github "tophat/RichTextView"

And run carthage update --platform iOS in your repo.

Usage

You can instantiate a RichTextView by importing the project first:

import RichTextView

To init a RichTextView:

let richTextView = RichTextView(
    input: "Test",
    latexParser: LatexParser(),
    font: UIFont.systemFont(ofSize: UIFont.systemFontSize),
    textColor: UIColor.black,
    isSelectable: true,
    isEditable: false,
    latexTextBaselineOffset: 0,
    interactiveTextColor: UIColor.blue,
    textViewDelegate: nil,
    frame: CGRect.zero,
    completion: nil
)

You can also update an existing RichTextView as follows:

richTextView.update(
    input: "Test",
    latexParser: LatexParser(),
    font: UIFont.systemFont(ofSize: UIFont.systemFontSize),
    textColor: UIColor.black,
    latexTextBaselineOffset: 0,
    interactiveTextColor: UIColor.blue,
    completion: nil
)

The parameters are defined as follows:

  • input - The string you want to render
  • latexParser - You can pass your own class that conforms to LatexParserProtocol if you want to handle LaTeX parsing in a custom way. Currently we use the iosMath Pod to handle LaTeX parsing by default
  • font - The font of the text to render
  • texColor - The color of the text to render
  • isSelectable - A property that determines whether or not RichTextView is selectable
  • isEditable - A property that determines whether or not RichTextView is editable
  • latexTextBaselineOffset - The baseline offset of the attributed text attachment that represents any LaTeX text that needs to be rendered
  • interactiveTextColor - The text color of any interactive elements/custom links (see Interactive element in Formatting the input)
  • textViewDelegate - A RichTextViewDelegate - conforms to UITextViewDelegate and also has handling when interactive elements/custom links are tapped
  • frame - A CGRect that represents the frame of the RichTextView
  • completion - A completion block to handle any errors that might be returned. The input will still render even if there are errors, however it might look differently than expected.

Formatting the input

In order for the RichTextView to handle the various use cases it might encounter, the input string needs to be formatted as follows:

  • LaTeX: Put any text you want to render as LaTeX in between two [math] and [/math] tags. Example: [math]x^n[/math]
  • Code: Put any text you want to render as code in between two [code] and [/code] tags. Example: [code]print('Hello World')[/code]
  • HTML/Markdown: No formatting necessary
  • YouTube Videos: Put the ID of the YouTube video in a YouTube tag as follows: youtube[dQw4w9WgXcQ]. The YouTube ID of any video can be found by looking at the URL of the video (Example: https://www.youtube.com/watch?v=dQw4w9WgXcQ) and taking the value right after the v= URL parameter. In this case the ID of the YouTube video is dQw4w9WgXcQ
  • Vimeo Videos: Put the ID of the Vimeo video in a Vimeo tag as follows: vimeo[100708006]. The Vimeo ID of any video can be found by looking at the URL of the video (Example: https://vimeo.com/100708006) and taking the value right after the first /. In this case the ID of the Vimeo video is 100708006
  • Interactive element: If you want to add text that has custom handling when you tap it, put the text in between two [interactive-element id=<id>] and [/interactive-element] tags. By doing this, when a user taps this text it will call the didTapCustomLink function of RichTextViewDelegate with the ID of the text that represents the interactive element (<id>), so be sure to hook into RichTextViewDelegate to capture this.

Screenshots

Check out the sample project in the Example root folder to see the screenshots above in action!

Architecture

Architecture

Contributing

Simply clone the repo, run pod install and you should be good to go

If you want to visually devQA your changes you can navigate to the Example project (found in the root Example folder), run pod install and then build and run the app. This will show you some common usages of the RichTextView.

The example project points to the local copy of the RichTextView pod, so any changes made locally will be reflected in the sample project.

However, you need to be on the legacy build system to see your changes reflected. There is a known issue with caching development Pods and XCode 10.

Feel free to add additional input/output examples to the example project, especially if you add any new functionality.

Also, be sure to run the unit/UI tests locally as part of the devQA process.

Credits

Thanks goes to these wonderful people (emoji key):


Ahmed Elkady

💻 🤔 ⚠️

Orla Mitchell

💻 🤔 👀

Jake Bolam

🚇📖

Sanchit Gera

📖

Monica Moore

🎨

Brandon Baksh

📖

Siavash Bidgoly

🚇

Stephen Truong

📖

Thanks to Carol Skelly for donating the Github organization and Kevin Zhow for donating the Pod name!

richtextview's People

Contributors

abinoda avatar aelkady avatar bisugit avatar brandonbaksh avatar dependabot-preview[bot] avatar dependabot[bot] avatar greenkeeper[bot] avatar ivan-magda avatar jakebolam avatar kushal-pandya avatar maicon-brauwers avatar mcataford avatar msrose avatar nebojsabrankovic avatar noahnu avatar noobish1 avatar orlam avatar sanchitgera avatar simon223 avatar struong9 avatar syavash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

richtextview's Issues

Add Swift Style Guide

What is the purpose of your issue?

  • Bug
  • Feature Request
  • Question
  • Other

Description

Add a Swift Style Guide for future collaborators to references

Make Rich Text View Editable

What is the purpose of your issue?

  • Bug
  • Feature Request
  • Question
  • Other

Description

It would be nice if we could make the rich text view editable, so users could add/erase content. Once they are done editing it would add the HTML/Markdown/any other relevant styling.

Add Tooltip to Rich Text View

What is the purpose of your issue?

  • Bug
  • Feature Request
  • Question
  • Other

Description

This would include the ability to, at a minimum, cut/copy/paste/select/select all text

How to show content with html format and correct Language format?

I spend a lot of time show this content as a description but I am failed to manage this can anyone guide how can display it

`A'ishah said that the Messenger of Allah used to start the prayer by
reciting the Takbir (Allahu Akbar; Allah is Greatest)
and then recite,

                                                                                                                               الْحَمْدُ للَّهِ رَبِّ الْعَـلَمِينَ

All praise and thanks be to Allah, the Lord of all that exists. (Ibn Abi Hatim 1:2).

Above content coming from the API from a Nobel Book, I have no control about content, HTML tag, and Arabic.

Problem description:

I able to show text with HTML tag but Arabic content always set it left the position. it should be right according to Arabic language rule.


Add macOS support

What is the purpose of your issue?

  • Bug
  • Feature Request
  • Question
  • Other

Description

Ensure that RichTextView can be used by macOS applications

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Generate array of labels and web views

This function should return an array of UILabel and WKWebView objects in the proper order, UILabels for non-video substrings and WKWebViews for video substrings.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Generic Bug Fixes After First Use

What is the purpose of your issue?

  • Bug
  • Feature Request
  • Question
  • Other

Description

  • UILabel text does not wrap around
  • Markdown styling not retained
  • HTML/Markdown parsing consistently leaves a trailing newline that needs to be trimmed
  • WebViews not rendering

Richtextview begin{align} not working.

How can i show this LaTex string in RichtextView?

"\begin{align}
\n\because \text{According to the question,}\\
\n\frac{1}{2}m(v_f)^2&=\frac{1}{2}\times\frac{1}{2}m(v_i)^2\\
\n(v_i,v_f=\text{initial and final speeds of the body}\\
\nor \quad\ (v_f)^2&=\frac{(v_i)^2}{2}\ or\ v_f=\frac{10}{\sqrt{2}}\\
\nGiven,\quad f&=-kv\\
\nor\quad ma&=-kv\Rightarrow\frac{mdv}{dt}=-kv\\
\n\Rightarrow\int_{10}^{\frac{10}{\sqrt{2}}}\frac{1}{v}dv&=-\int_{0}^{10}kdt\tag{ m=1kg}\\
\n\Rightarrow(ln\ v)_{10}^{\frac{10}{\sqrt{2}}}&=-k(10)\\
\n\Rightarrow ln\ \frac{10}{\sqrt{2}} - ln\ 10&=-k(10)\\
\n\Rightarrow k=\frac{1}{10}ln\frac{10}{10/\sqrt{2}}&=\frac{1}{10}ln \sqrt{2}=\frac{ln\ 2}{20}
\n
\n\end{align}"

Set up constraints of labels and web views

Implement a function that adds all the UILabel and WKWebView objects as subviews of THMRichTextView and constrain appropriately (first view constrained to the top of THMRichTextView, last view constrained to the bottom of THMRichTextView, tops and bottoms of middle views chain-constrained together)

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Add ability to update input

What is the purpose of your issue?

  • Bug
  • Feature Request
  • Question
  • Other

Description

We need to add the ability for users of RichTextView to be able to update the input text on the fly.

the baseline of the text is always on the bottom, could you make it codable?

What is the purpose of your issue?

  • Feature: make the baseline/alignment of the text codable

Description

when I put a some normal text and big math formula at the same line. The baseline is at the bottom of the textview, so the formula looks too tall *&^%, that looks weird.
I hope the baseline stand in the center or make it codable

href link

What is the purpose of your issue?

  • Bug
  • Feature Request
  • Question
  • Other

Description

Provide as much information possible about the issue below

<a href='https://www.google.com'>jump to page</a>

How can I do?
thank you

Add RichTextView input callback

What is the purpose of your issue?

  • Feature Request
  • Question
  • Other

Description

Provide as much information possible about the issue below
I want listen content of the RichTextView when input or delete some content.

Implement RichLabelGenerator

Takes as input a string of rich text and outputs a label with the correct attributed text set. Feed a class that conforms to the latex parser protocol to RichTextParser

Make RichTextView ObjC Compatible

What is the purpose of your issue?

  • Bug
  • Feature Request
  • Question
  • Other

Description

Add compatibility to RichTextView such that it can be used in ObjC projects

An in-range update of docusaurus is breaking the build 🚨

The devDependency docusaurus was updated from 1.6.2 to 1.7.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

docusaurus is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: build: CircleCI is running your tests (Details).
  • ci/circleci: website: Your tests failed on CircleCI (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Add support for images

What is the purpose of your issue?

  • Bug
  • Feature Request
  • Question
  • Other

Description

Add support for images as an additional rich text type. Input format TBD.

Add LaTeX parsing functionality

Implement protocol that extracts anything in a [math][/math] tag from an input string and replaces it (tags included) with an image/string.

Ideally this should use the Down LaTeX parser but if not we can use iosMath. Output will be determined by which path we take.

Use AST HTML parsing available in latest Down library

What is the purpose of your issue?

  • Feature Request
  • Question
  • Other

Description

Down has recently updated to use AST parsing to generate an NSAttributedString from HTML instead of the usual NSAttributedString way of doing it. However, this has broken some tests and functionality in this library. The purpose of this ticket is to update to the latest Down library and fix anything that's broken.

RichTextView inside CollectionViewCell

What is the purpose of your issue?

  • Bug
  • Question
  • Other

Description

I am beginner to swift programming.
I am trying to use richtextview inside uicollectionview cell. My collectionview cell contain one richtextview and one imageview both embedded in a stackview.
But the problem i am facing is as soon as collectionview cell loads all cells disappears and i can only see the scroll indicator.

Edit: If I update input inside cellForItemAt only then this happens.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

How to show Latex text?

Latex String is not showing proper equation, Here I have one string like

"From a circular card board of uniform thickness and mass M, a square disc of maximum possible area is cut. If the moment of inertia of the square with the axis of rotation at the centre and perpendicular to the plane of the disc is $\frac{Ma^2}{6}$, the radius of the circular card board is"

how to display it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.