DailyTags - a flexible markdown library that supports custom tags and markups

Overview

DailyTags

API

DailyTags is a flexible markdown library that supports custom tags and markups.

The library parses a given markup into rich text for Jetpack Compose. DailyTags comes with Markdown and HTML support by default (please, see the supported features) and is very easy to extend to support custom markups.

daily tags demo picture

The library parses text source into nodes which are then styled using AnnotatedString. No WebView is required. All you need is to create a rule that defines how the text is extracted and styled. More examples below!

DailyTags aims to be:

  • fast
  • 🪶 lightweight(less than 50kb)
  • 👋 easy to use
  • 🏗️ extensible
  • 📎 flexible

The library provides defaults to display Markdown content along with giving all the means to tweak the appearance as much as you wish!This repository contains DailyTags source code and a sample app.

📦 Installation

Add the following configuration to the build.gradle files:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation "com.github.DmytroShuba:DailyTags:1.0.0"
}

🔨 Usage

Markdown

DailyTags supports most of the Markdown features, but not all (the supported features).

To parse Markdown content use SimpleMarkupParser and MarkdownRules together:

Hello world" val rules = MarkdownRules.toList() val parser = SimpleMarkupParser() val content = parser .parse(source, rules) .render() .toAnnotatedString() Text(text = content)">
val source = "Hello world"
val rules = MarkdownRules.toList()
val parser = SimpleMarkupParser()
val content = parser
    .parse(source, rules)
    .render()
    .toAnnotatedString()

Text(text = content)

Markdown and HTML

Hello world" val rules = MarkdownRules.toList() + HtmlRules.toList() val parser = SimpleMarkupParser() val content = parser .parse(source, rules) .render() .toAnnotatedString() Text(text = content)">
val source = "Hello world"
val rules = MarkdownRules.toList() + HtmlRules.toList()
val parser = SimpleMarkupParser()
val content = parser
    .parse(source, rules)
    .render()
    .toAnnotatedString()

Text(text = content)

Custom tags

  1. Create a pattern with a regular expression to find the specified content.
([\s\S]+?)<\/hl-blue>")">
val PATTERN_HIGHLIGHT_BLUE = Pattern.compile("^
   
    ([
    \s\S]+?)<
    \/hl-blue>
    "
   )
  1. Create rules for your patterns. A rule includes the pattern and styling configuration for the matched content:
val blueRule = PATTERN_HIGHLIGHT_BLUE.toRule(spanStyles = SpanStyle(color = Color.Blue))
  1. Use custom rules when parsing the content:
val parser = SimpleMarkupParser()
val rules = listOf(blueRule, ...)
val content = parser
    .parse(source, rules)
    .render()
    .toAnnotatedString()

See a detailed step by step guide here.

🔎 Wiki

More documentation is going to be released soon so stay tuned! For more information you can:

  • visit DailyTags Wiki page
  • see the sample application that is included to this repository
  • explore source code to see how Markdown is implemented.

If you have a problem using DailyTag please see Troubleshooting page. It might be already answered!

📄 License

The MIT License (MIT)

Copyright (c) 2022 Dmytro Shuba

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
 🗨️ Beautiful Dialog is a Simple and Beautiful custom dialog
🗨️ Beautiful Dialog is a Simple and Beautiful custom dialog

Beautiful Dialog 🗨️ Beautiful Dialog is a Simple and Beautiful custom dialog. Screenshots Including in your project Gradle Add below codes to your ro

(Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.
(Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.

BottomBar (Deprecated) I don't have time to maintain this anymore. I basically wrote the whole library in a rush, without tests, while being a serious

Custom android music player view.
Custom android music player view.

InteractivePlayerView Custom android music player view. Screen Check it on youtube Usage(XML) Define it in your xml file. co.mobiwise.library.Intera

Custom wheel widget for android
Custom wheel widget for android

Wheel widget for Android To include the wheel widget in the current layout, you should add in the layout xml this lines: it.sephiroth.android

IconicDroid is a custom Android Drawable which allows to draw icons from several iconic fonts.
IconicDroid is a custom Android Drawable which allows to draw icons from several iconic fonts.

IconicDroid IconicDroid is a custom Android Drawable which allows to draw icons from several iconic fonts. Try out the sample application on the Googl

Set custom font in Android application

MagicViews Provides a simple way to set custom font in Android application. Adding to your project Add the library as a dependency to your build.gradl

A beautiful Android custom View that works similar to a range or seekbar. With animations.
A beautiful Android custom View that works similar to a range or seekbar. With animations.

ValueBar A beautiful Android custom View that works similar to a range or seekbar. Selection by gesture. With animations. Supporting API level 11+. De

An android custom view that displays a circle with a colored arc given a mark
An android custom view that displays a circle with a colored arc given a mark

MarkView An android custom view that displays a circle with a colored arc given a mark. Usage Add as a dependency compile 'com.github.xiprox.markv

This is a android custom view , like a scratch card effect!
This is a android custom view , like a scratch card effect!

ScratchView This is a android custom view , like a scratch card effect! Last Update 采纳DearZack童鞋的优化思路,把计算擦除面积比例的操作放在手指离开屏幕时,以降低对CPU的占用。 Articles Scrat

Comments
  • Html - Bold text in ListItem

    Html - Bold text in ListItem

    Great library, thank you for this. Just found one issue. I cannot add a bold text segment inside an unordered list.

    <li>Tap to open the <b>phone settings</b> and search for <b>Device Care</b></li>

    this is rendering a list item but the text contain the bold tags. Is this on purpose? How can I achieve that the bold segments are rendered bold as well?

    good first issue 
    opened by fairEnough83 1
  • Error parsing two <a href> tags in the same string

    Error parsing two tags in the same string

    When there are more than one tag in the string, the first closing is ignoring, so all text from first until last is highlighted, or even the first text is not rendered at all.

    Example test to reproduce it:<![CDATA[ I <b>accept</b> the <a href=\"www.bing.com">Terms and Conditions</a> and have read the <a href=\"www.google.es\">Privacy Notice</a>]]>

    opened by PabloMGrela 1
  • Not able to use it ,Failed to resolve: com.github.DmytroShuba:DailyTags:1.0.0

    Not able to use it ,Failed to resolve: com.github.DmytroShuba:DailyTags:1.0.0

    i have added implementation "com.github.DmytroShuba:DailyTags:1.0.0" in app level build.gradle and buildscript { repositories { maven { url 'https://jitpack.io' } } ext { compose_version = '1.0.1' } }// Top-level build file where you can add configuration options common to all sub-projects/modules. this in project level build.gradle file

    question 
    opened by vishalx4 1
  • JVM release

    JVM release

    Hi, most of the features should be available on JVM, as compose is available in non-Android artifacts as well. Do you think you could release the library so that it could be used on Compose desktop as well?

    opened by MrStahlfelge 0
Releases(1.0.0)
Owner
Dmytro
Android Software Engineer
Dmytro
A new canvas drawing library for Android. Aims to be the Fabric.js for Android. Supports text, images, and hand/stylus drawing input. The library has a website and API docs, check it out

FabricView - A new canvas drawing library for Android. The library was born as part of a project in SD Hacks (www.sdhacks.io) on October 3rd. It is cu

Antwan Gaggi 1k Dec 13, 2022
An Android library supports badge notification like iOS in Samsung, LG, Sony and HTC launchers.

ShortcutBadger: The ShortcutBadger makes your Android App show the count of unread messages as a badge on your App shortcut! Supported launchers: Sony

Leo Lin 7.2k Dec 30, 2022
Android layout decorators : Injecting custom attributes in layout files, Using decorators to get rid of unnecessary class explosion with custom views

Decor Decor is a library that applies decorators to Android layout with additional attributes without the need to extend and create a custom View for

Mouna Cheikhna 304 Nov 25, 2022
A Material design Android pincode library. Supports Fingerprint.

LolliPin A Lollipop material design styled android pincode library (API 14+) To include in your project, add this to your build.gradle file: //Loll

Omada Health 1.6k Nov 25, 2022
Drag and drop to reorder items in a list, grid or board for Android. Based on RecyclerView. Also supports swiping items in a list.

DragListView DragListView can be used when you want to be able to re-order items in a list, grid or a board. It also supports horizontal swiping of it

Magnus Woxblom 658 Nov 30, 2022
Useful library to use custom fonts in your android app

EasyFonts A simple and useful android library to use custom fonts in android apps without adding fonts into asset/resource folder.Also by using this l

Vijay Vankhede 419 Sep 9, 2022
Android Library for Custom Switches.

Android Library for Custom Switches.

Angad Singh 376 Jan 4, 2023
Custom UI control for android which is showing data as a segments and a value inside them.

Segmented Bar View for Android Custom UI control for android which is showing data as a segments and a value inside them. Screenshots Install From rep

GSPD 354 Nov 10, 2022
a custom view that provides dragged and scaled

DragScaleCircleView A custom imageview that provides the circle window can be dragged and scaled, crop image. How does it look? Why? Sometimes need to

null 514 Dec 22, 2022
Custom & highly configurable seek slider with sliding intervals, disabled state and every possible setting to tackle!

LabeledSeekSlider Custom & highly configurable seek slider with sliding intervals, disabled state and every possible setting to tackle! Minimum target

Edgar Žigis 78 Sep 27, 2022