{"id":16274165,"url":"https://github.com/trinker/hilight","last_synced_at":"2025-04-08T16:28:09.805Z","repository":{"id":146663631,"uuid":"41976491","full_name":"trinker/hilight","owner":"trinker","description":null,"archived":false,"fork":false,"pushed_at":"2017-04-14T12:46:14.000Z","size":176,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-14T13:16:11.530Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trinker.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-09-05T21:40:21.000Z","updated_at":"2017-04-22T16:01:39.000Z","dependencies_parsed_at":"2023-04-14T16:18:28.620Z","dependency_job_id":null,"html_url":"https://github.com/trinker/hilight","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Fhilight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Fhilight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Fhilight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trinker%2Fhilight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trinker","download_url":"https://codeload.github.com/trinker/hilight/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247880954,"owners_count":21011775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T18:27:24.887Z","updated_at":"2025-04-08T16:28:09.763Z","avatar_url":"https://github.com/trinker.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntitle: \"hilight\"\ndate: \"`r format(Sys.time(), '%d %B, %Y')`\"\noutput:\n  md_document:\n    toc: true      \n---\n\n```{r, echo=FALSE}\ndesc \u003c- suppressWarnings(readLines(\"DESCRIPTION\"))\nregex \u003c- \"(^Version:\\\\s+)(\\\\d+\\\\.\\\\d+\\\\.\\\\d+)\"\nloc \u003c- grep(regex, desc)\nver \u003c- gsub(regex, \"\\\\2\", desc[loc])\nverbadge \u003c- sprintf('\u003ca href=\"https://img.shields.io/badge/Version-%s-orange.svg\"\u003e\u003cimg src=\"https://img.shields.io/badge/Version-%s-orange.svg\" alt=\"Version\"/\u003e\u003c/a\u003e\u003c/p\u003e', ver, ver)\n````\n\n[![Build Status](https://travis-ci.org/trinker/hilight.svg?branch=master)](https://travis-ci.org/trinker/hilight)\n[![Coverage Status](https://coveralls.io/repos/trinker/hilight/badge.svg?branch=master)](https://coveralls.io/r/trinker/hilight?branch=master)\n`r verbadge`\n\n**hilight** is an **R** package to allow for easier highlighting of text substrings as an HTML file.  \n\n# Usage\n\nThe user goes through the following process:\n\n1. Generate a template via `highlight_template` with css markup for `mark` tags with classes and colors\n2. Generate a body using the `mark` family of functions (more below)\n3. Insert the body into `highlight_template` output with `insert_body`\n4. Generate an HTML file with `tempalte2html`\n\nThe user can generate a highlight marked body character vector to insert into the html document using four functions:\n\n| Function         |  Description                                          |\n|------------------|-------------------------------------------------------|\n| `mark_words`      | Highlight specific words                       |\n| `mark_word_stems`      | Highlight word stems                       |\n| `mark_regex`   | Highlight by regex                     |\n| `mark_sentences`   | Highlight sentences by `grepl`                      |\n\nThese mark functions markup the body string with html `mark` tags with a class that was supplied to `highlight_template`.  These also correspond to a color in the css in the `highlight_template` output.\n\n# Installation\n\nTo download the development version of **hilight**:\n\nDownload the [zip ball](https://github.com/trinker/hilight/zipball/master) or [tar ball](https://github.com/trinker/hilight/tarball/master), decompress and run `R CMD INSTALL` on it, or use the **pacman** package to install the development version:\n\n```r\nif (!require(\"pacman\")) install.packages(\"pacman\")\npacman::p_load_gh(\"trinker/hilight\")\n```\n# Examples\n\nFirst and foremost the user will want to markup some content to insert into the template body.  The following examples show how to mark up the content and generate a highlighted HTML document.\n\n## Mark Words\n\nHighlight specific words.  Also note the **dplyr** syntax that may make ordering a bit more understandable.  Notice that we generate highlighted content and then put that into an HTML template.\n\n```{r, eval=FALSE}\nx \u003c-\"I like good cheese but hate Bad cheese\"\nwords \u003c- c(\"cheese\", \"like\", \"good\", \"bad\")\nmarks_class \u003c- c(\"neutral\", \"pos\", \"pos\", \"neg\")\nmarks \u003c- c(pos = \"lightgreen\", neg = \"pink\", neutral = \"yellow\")\nbody \u003c- mark_words(x, words, marks_class)\n\n## To an external file\ntemplate2html(insert_body(highlight_template(marks), body))\nopen_html()\n\n## dplyr Syntax\nlibrary(dplyr)\n\nmarks %\u003e%\n    highlight_template() %\u003e%\n    insert_body(body) %\u003e%\n    template2html()\n\nopen_html()\n```\n\n![](tools/figure/c1.png)\n\n## Mark Word Stems\n\nHighlight word stems. For example `cheese` matches \"cheese\" and \"cheeses\".  Give the shortest possible substring as a stem.\n\n```{r, eval=FALSE}\nx \u003c-\"I like good cheeses but she hated Bad cheese\"\nstems \u003c- c(\"cheese\", \"like\", \"good\", \"bad\")\nmarks_class \u003c- c(\"neutral\", \"pos\", \"pos\", \"neg\")\nmarks \u003c- c(pos = \"lightgreen\", neg = \"pink\", neutral = \"yellow\")\nbody \u003c- mark_word_stems(x, stems, marks_class)\n\n## To an external file\ntemplate2html(insert_body(highlight_template(marks), body))\nopen_html()\n```\n\n![](tools/figure/c2.png)\n\n## Mark Regex\n\nHighlight based on regexes.  Ths is the most flexible but takes knowledge of regular expressions.\n\n```{r, eval=FALSE}\nx \u003c-\"I like good cheeses but she hated Bad cheese.  Really hates it\"\nregex \u003c- c(\"chees[^ ]*\\\\b\", \"like\", \"hate[^ ]*\\\\b\", \"good\", \"bad\\\\b\")\nmarks_class \u003c- c(\"neutral\", \"pos\", \"neg\", \"pos\", \"neg\")\nmarks \u003c- c(pos = \"lightgreen\", neg = \"pink\", neutral = \"yellow\")\n\nbody \u003c- mark_regex(x, regex, marks_class)\n\n## To an external file\ntemplate2html(insert_body(highlight_template(marks), body))\nopen_html()\n```\n\n![](tools/figure/c3.png)\n\n## Mark Sentences\n\nHighlight sentences if they meet a condition (If multiple conditions are met the first condition that is met will be highlighted).  This essentially splits content into sentences and uses a `grepl` to determine if a condition is met.\n\n### Example 1: Words\n\n```{r, eval=FALSE}\nx \u003c- c(\"I like good cheeses but she hated Bad cheese.  Do you?\",\n    \"This is realy bad!\", \"I drank water.  I wanted juice but like it. Why not?\")\n\nregex \u003c- c(\"chees[^ ]*\\\\b\", \"like\", \"hate[^ ]*\\\\b\", \"good\", \"bad\\\\b\")\nmarks_class \u003c- c(\"neutral\", \"pos\", \"neg\", \"pos\", \"neg\")\nmarks \u003c- c(pos = \"lightgreen\", neg = \"pink\", neutral = \"yellow\")\n\nbody \u003c- mark_sentences(x, regex, marks_class)\n\n## To an external file\ntemplate2html(insert_body(highlight_template(marks), body))\nopen_html()\n```\n\n![](tools/figure/c4.png)\n\n### Example 2: End Marks\n\n```{r, eval=FALSE}\nregex \u003c- c(\"\\\\.$\", \"\\\\?$\", \"\\\\!$\")\nmarks_class \u003c- c(\"statment\", \"question\", \"exclamation\")\nmarks \u003c- c(statment = \"lightgreen\", question = \"pink\", exclamation = \"orange\")\n\nbody \u003c- mark_sentences(x, regex, marks_class)\n\n## To an external file\ntemplate2html(insert_body(highlight_template(marks), body))\nopen_html()\n```\n\n![](tools/figure/c5.png)\n\n# Contact\n\nYou are welcome to:\n* submit suggestions and bug-reports at: \u003chttps://github.com/trinker/hilight/issues\u003e\n* send a pull request on: \u003chttps://github.com/trinker/hilight/\u003e\n* compose a friendly e-mail to: \u003ctyler.rinker@gmail.com\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrinker%2Fhilight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrinker%2Fhilight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrinker%2Fhilight/lists"}