Giter Club home page Giter Club logo

mindr's Introduction

mindr: an R package that converts markdown (.md) or rmarkdown (.Rmd) files to mind maps, and vice versa

CRAN downloads

Introduction

With 'mindr' you can draw a mind map in markdown syntax, or start a markdown document from a mind map!

mindr is an R package which converts markdown (.md) or rmarkdown (.Rmd) files to mind maps (.mm), and vice versa. Mind map files (.mm) can be opened by or imported to common mindmap software such as the desktop software 'FreeMind'and 'XMind', or the online webware 'mindmeister'. Plenty of cross-platform mindmap software suits are available (see the list).

  • If your are a user of markdown or rmarkdown or bookdown or blogdown, mindr can convert your .md or .Rmd files into mind maps easily. Furthermore, you can write a new mind map with markdown syntax and use mindr to convert it into an .mm mind map.
  • If you are a mind map user, you can export your mind map into an .mm file and use mindr to convert it into a markdown file as an outline of your new document or book.

If you don't know what is markdown, here is a demo file.

Quick start

Installation

# stable version:
install.packages("mindr")
# or development version:
devtools::install_github("pzhaonet/mindr")

Convert between mind maps, markdown files, texts and directories

library('mindr')
# Example 1: From Markdown to other outputs ####

## Source document ####
input <- system.file("examples/mindr-md.Rmd", package = "mindr")

## file.show(input) # Open the input file with the default program, if any
input_txt <- readLines(input, encoding = "UTF-8")

## Convert to mind map text, markdown outline, R script, and HTML widget ####
mm_output <- mm(input_txt, output_type = c("mindmap", "markdown", "R", "widget"))
mm_output

## Save the output texts as files ####

### mind map ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".mm")
writeLines(mm_output$mindmap, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### markdown outline ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".md")
writeLines(mm_output$markdown, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### R script ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".R")
writeLines(mm_output$r, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### Widget ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".html")
htmlwidgets::saveWidget(mm_output$widget, file = output)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

## Generate directory according to the source document ####
temp_dir <- file.path(tempdir(), "mindr")
mm_output <- mm(input_txt, output_type = "dir", root = "mindr", md_list = TRUE,
    md_braces = TRUE, md_bookdown = TRUE, dir_to = temp_dir)
# system2('open', temp_dir) # Open the generated directory unlink(temp_dir,
# recursive = TRUE) # remove the generated directory

## More arguments ####
mm_output <- mm(input_txt, output_type = c("mindmap", "markdown", "R", "widget"),
    root = "mindr", md_list = TRUE, md_braces = TRUE, md_bookdown = TRUE)
mm_output

# Example 2: From mind map to other outputs ####

## Source document ####
input <- system.file("examples/mindr-mm.mm", package = "mindr")

## file.show(input) # Open the input file with the default program, if any
input_txt <- readLines(input, encoding = "UTF-8")

## Convert markdown outline, R script, and HTML widget ####
mm_output <- mm(input_txt, output_type = c("markdown", "R", "widget"))
mm_output

## Save the output texts as files ####

### markdown outline ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".md")
writeLines(mm_output$markdown, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### R script ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".R")
writeLines(mm_output$r, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### Widget ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".html")
htmlwidgets::saveWidget(mm_output$widget, file = output)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

## Generate directory according to the source document ####
temp_dir <- file.path(tempdir(), "mindr")
mm_output <- mm(input_txt, output_type = "dir", root = "mindr", dir_to = temp_dir)
# system2('open', temp_dir) # Open the generatecd directory unlink(temp_dir,
# recursive = TRUE) # remove the generated directory

# Example 3: From R script to other outputs ####

## Source document ####
input <- system.file("examples/mindr-r.R", package = "mindr")

## file.show(input) # Open the input file with the default program, if any
input_txt <- readLines(input, encoding = "UTF-8")

## Convert to mind map text, markdown text, and HTML widget ####
mm_output <- mm(input_txt, output_type = c("mindmap", "markdown", "widget"))
mm_output

## Save the output texts as files ####

### mind map ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".mm")
writeLines(mm_output$mindmap, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### R markdown ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".Rmd")
writeLines(mm_output$markdown, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### Widget ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".html")
htmlwidgets::saveWidget(mm_output$widget, file = output)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

## Generate directory according to the source document ####
temp_dir <- file.path(tempdir(), "mindr")
mm_output <- mm(input_txt, output_type = "dir", root = "mindr", dir_to = temp_dir)
# system2('open', temp_dir) # Open the generated directory unlink(temp_dir,
# recursive = TRUE) # remove the generated directory

# Example 4: From directory to other outputs ####

## Source directory ####
input <- system.file(package = "mindr")

## Convert to mind map text, markdown outline, R script, and HTML widget ####
mm_output <- mm(input, output_type = c("mindmap", "markdown", "R", "widget"))
mm_output

## Save the output texts as files ####

### mind map ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".mm")
writeLines(mm_output$mindmap, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### markdown outline ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".md")
writeLines(mm_output$markdown, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### R script ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".R")
writeLines(mm_output$r, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### Widget ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".html")
htmlwidgets::saveWidget(mm_output$widget, file = output)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

## Clone the source directory ####
temp_dir <- file.path(tempdir(), "mindr")
mm_output <- mm(input, output_type = "dir", dir_to = temp_dir)
# system2('open', temp_dir) # Open the generated directory unlink(temp_dir,
# recursive = TRUE) # remove the generated directory

Create Interactive Web MindMap with the JavaScript 'markmap' Library

Run:

example(markmap)

then you will see a demo interactive mind map in the viewer of your R session.

More themes can be seen if you run:

example(markmapOption)

To create your own interactive mind map, create a folder named mm in the working directory (getwd()), and drop some .mm files into mm/. Run:

markmap()

Extract the outline from (a) markdown files

Run:

library('mindr')
example(outline)

then you will get a demo outline file outline.md in the working directory (getwd()).

To extract the outline from your own markdown files, create a folder named mm in the working directory (getwd()), and drop some markdown or rmarkdown files into mm/. Run:

outline()

Have fun!

Still being developed. Feel free to give your feedback to me!

Showcase

  • Mindmap of my book Learning R (in Chinese. to be published soon.)

Updates

Version 1.3:

  • Re-write the whole package.
  • Rename and new arguments.
  • The all-in-one wrapper function mm().
  • Complete individual functions md2mm(), mm2md(), r2mm(), mm2r(), dir2mm(), mm2dir(), r2md(), md2r(), r2dir(), dir2r().
  • The markmap() function supports more input types.
  • Remove unnecessary dependencies (on pandoc, tree, jsonlite, data.tree).
  • Remove redundant functions.
  • Give more exmaples.

New updates after 2019-01-25 are not logged here. Please see the commits.

  • 2019-01-25. v1.2.0. universal function mm().
  • 2018-12-16. v1.1.9. Added an option of 'pandoc' to extract headings.
  • 2018-11-10. v1.1.8. Adapted to the roxygen style when conversion between .R scripts and .Rmd documents.
  • 2018-10-26. v1.1.7. Conversion between .R scripts and .Rmd documents.
  • 2018-10-21. v1.1.6. Support LaTeX equations.
  • 2018-10-11. v1.1.5. Improve the support for bookdown projects. Bugs fixed.
  • 2018-09-28. v1.1.2. Display .mm mind maps. Keep hyperlinks. dir2() for creating mindmaps from folder structure.
  • 2018-04-17. v1.1.1. Support tibble dataframes.
  • 2017-07-19. v1.1.0. On CRAN. See CHANGES IN mindr VERSION 1.1.
  • 2017-07-05. v1.0.6. Rmarkmap added. Run example(markmap).
  • 2017-07-03. v1.0.5. Better backup.
  • 2017-06-19. v1.0.4. Released on CRAN!
  • 2017-06-02. v1.0.0. Backup existing files before overwritten. Submitted to CRAN.
  • 2017-05-21. v0.2.0. Rename functions.
  • 2017-05-21. v0.1.0. Bidirectional! Now mind maps can be converted to markdown.
  • 2017-05-20. v0.0.1. Can Save the outline.
  • 2017-05-19. v0.0.0. A very preliminary version.

To do

  • RStudio addin to convert text into a mindmap widget.

License

Copyright 2021 Peng Zhao.

Released under the GPL-3 license.

mindr's People

Contributors

batpigandme avatar pzhaonet 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  avatar

mindr's Issues

Radial mind map rather than tree?

Hi,

Currently the only option that seems to be available is a tree layout - if you want a radial mind map (like your Chinese-language Learning R example), it seems it has to be opened in e.g. xMind. Is this accurate? Do you plan to add a "traditional" mind map layout option like this at any point? (I want to incorporate a mind map into a shiny app, so it doesn't make sense to force the user to go to another piece of software to get the result.)

markmap only shows a root node

Hi,

The example in the wiki works fine. But when I try to use the markmap function with an mm file I created does not work (I put the file in the mm folder in the working directory as directed). I tried to copy the mm file generated in the example to the mm folder in working directory but that isn't working either. Please help me out.

Problem with a simple md file

I am having problem lifting the following md snippet to mm format. The error I am getting is

Error in if (diffncc[i] == 1) mm[i + 2] <- paste0("<node TEXT=\"", mmtext[i],  : 
  missing value where TRUE/FALSE needed

A

  • B
    • C
  • D
    • E
    • F

Question: include notes from md2mm

Hi,

Can I include the notes (i.e., the text under each header) as well as the header in the md2mm() and mm2md()?

I've tried, but this does not seem to work.
Thanks,
Atanas

Is this package maintained?

Hello,

Recently I discovered this package, but when I tried to check it on CRAN I got the following message there:

Package ‘mindr’ was removed from the CRAN repository.

Formerly available versions can be obtained from the archive.

Archived on 2023-08-28 as email to the maintainer is undeliverable.

A summary of the most recent check results can be obtained from the check results archive.

Please use the canonical form https://cran.r-project.org/package=mindr to link to this page.

Is this package maintained?

mm2md: allow max.level arg

For more general use, in md2mm you should at least allow a max.level argument to select the maximum level in markdown files that will be shown in the mindmap.

max.level = 1: show only chapter level
max.level = 2: show only chapter/section level
...

Ampersand symbol(&) causes an error when converted into mm

Hello,

If you convert any md file that contains ampersand symbol (&) into mm, the created mm file is not open properly in any mindmap clients.

I have also attempted to switch the symbol to amp; in the original md file, but it is not translated back into ampersand (&) in the mm file.

Would you mind resolving this issue?

How to apply 'mindr' in R shiny

I try to embed the mind into shiny webpage, but it return an error that the parameter length is zero.
(Can be used normally in R studio)
code:

library('miner')

...

input <- system.file("xuer.md", package = "mindr"),
mm(from = input, type = "file", root = "Ins", to = "learningr.mm"),

...

tibble to mindmap?

What about other data sources?
Typically workflow goes

  1. Read data
  2. Make tibble
  3. outputs (mindmaps)

How can we make mindmaps based on tibbles?

Is it possible to output the md mm or rmd to a html format with some javascript ?

Hello Zhao thank you for making this available ! I'm just wondering if you are planning to add a html output because I think it would be great to share the mm on web. Maybe you will say that it suffices to convert the mm to png but in this case some rich-text features such as hyperlink (a feature that you'll add based on your reponse to an issue) would be lost.

Tks again !

collapsed child nodes at start

Hi there,

Thanks for the wonderful package. anyway to start with the child nodes collapsed ? ( with markmap function)

Mindmap labels with link to URL

I want to create a mindmap from markdown.
How can I ensure that the mind map node label reacts on clicking containing a link to a URL?

outline() usage

Thank you for developing such an amazing tool!
I have a question about the function outline(). When running outline(), There just is an outline.md file got in the working directory. How can I get the outline plot with the outline() function? Thanks!
image

Add filter for file types

Thanks a lot for making the mindr package available. I like the idea a lot.
The outline() function looks for files with any extension in a given directory, which can cause problems, if there are other files than .Rmd or .md.
My .Rmd files are located in a directory, which also contains PDF and other files, which also contain lines starting with #. This in turn causes the function call to strsplit() in the md2mm() function to crash.
To avoid this problem, it might be a good idea to add an additional (optional) option to the md2mm() function to filter for files with a certain extension, like, for example .Rmd or .md.

Links

Hi, great package !

Would it be possible to include clickable links in the nodes of a markmap widget ?
I tried to insert markdown links, but they are converted into simple text...

Thanks

Pascal

Freeplane integration

Hello,

I was trying to take a freeplane mindmap (attached) to mindr and produce an rmd that could be later used as an HTML. I failed miserably -_-

I did

library(mindr)

mm(
  from = "statistics_outbreaks.mm",
  type = "file",
  to = "test.Rmd"
  )

and got:

The mm2md() function is to be deprecated soon. Please use mm() instead.
Error in rep("#", x) : invalid 'times' argument

What -_-?

I'd like to keep the format as much as possible. The buzzan theme, background, latex formulas.

Please help! I appreciate any effort.

Thank you very much,

Peter

R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS:   /usr/lib/libblas.so.3.10.0
LAPACK: /usr/lib/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] here_1.0.1    mindr_1.2.2.1

loaded via a namespace (and not attached):
 [1] compiler_4.1.0    prettyunits_1.1.1 remotes_2.4.0     tools_4.1.0      
 [5] testthat_3.0.2    digest_0.6.27     pkgbuild_1.2.0    pkgload_1.2.1    
 [9] jsonlite_1.7.2    evaluate_0.14     memoise_2.0.0     lifecycle_1.0.0  
[13] rlang_0.4.11      rstudioapi_0.13   cli_2.5.0         curl_4.3.1       
[17] yaml_2.2.1        xfun_0.24         fastmap_1.1.0     withr_2.4.2      
[21] knitr_1.33        desc_1.3.0        fs_1.5.0          htmlwidgets_1.5.3
[25] devtools_2.4.2    rprojroot_2.0.2   incidence_1.7.3   glue_1.4.2       
[29] distcrete_1.0.3   R6_2.5.0          processx_3.5.2    rmarkdown_2.8    
[33] sessioninfo_1.1.1 callr_3.7.0       purrr_0.3.4       magrittr_2.0.1   
[37] ps_1.6.0          ellipsis_0.3.2    htmltools_0.5.1.1 usethis_2.0.1    
[41] cachem_1.0.5      crayon_1.4.1

root option not working when input is ".mm"

mindr verion 1.2.3
Rstudio 1.4.1106
R version 3.6.3 (2020-02-29)

Command tried:
markmap(root = "Anything",input = c(".mm"),path = script.dir)

Example Test.mm file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<map version="0.8.1">
<node CREATED="1623522628521" ID="60ao52t4nh2h8987s9965isc46" MODIFIED="1623522628521" TEXT="Something">

<node CREATED="1623522628521" ID="41dth2m4dbqnpeguej32lelohr" MODIFIED="1623522628521" POSITION="right" TEXT="1st">
<node CREATED="1623522628521" ID="7joctu1mp193on1dkv8pq64cpl" MODIFIED="1623522628521" TEXT="Test1"/>

<node CREATED="1623522628521" ID="1k3uquq7gebn8r3jlto1750665" MODIFIED="1623522628521" TEXT="Test2"/>

</node>
<node CREATED="1623522628521" ID="17u81cbdjj82o4fqab06atcf65" MODIFIED="1623522628521" POSITION="right" TEXT="2nd">
<node CREATED="1623522628521" ID="7bfvjddtb8ejufgetfmil77ip6" MODIFIED="1623522628521" TEXT="Test3"/>

</node>
<node CREATED="1623522628521" ID="4t7vlg4bl3enbdao6qj9kaumq2" MODIFIED="1623522628521" POSITION="right" TEXT="3rd">
<node CREATED="1623522628521" ID="20reb74ko4dr4cj5862lsilm58" MODIFIED="1623522628521" TEXT="Test 4"/>

<node CREATED="1623522628521" ID="0d65airq3l0vljtj9vj32lcuhc" MODIFIED="1623522628521" TEXT="Test5"/>

</node>
</node>
</map>

Result:
result

How to run in command line OR GitHub actions?

Note: this is not an issue. It's more of a query

Hi,

Thanks for this very useful package.
I'm hoping to use this tool to convert my freemind *.mm files to markdown. Any quick guidance on how I can either:

  1. run from command line
  2. run in GitHub actions

Appreciate 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.