r
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.6KB

  1. #' @import xml2
  2. get_style_distribution <- function(docx) {
  3. docx <- "custom-reference.docx"
  4. dxml <- read_xml(unz(docx, filename = "word/document.xml"))
  5. sxml <- read_xml(unz(docx, filename = "word/styles.xml"))
  6. txml <- read_xml(unz(docx, filename = "word/theme/theme1.xml"))
  7. st <- xml_find_all(sxml, "/w:styles/w:style")
  8. all_desc <- data.frame(
  9. stringsAsFactors = FALSE,
  10. style_type = xml_attr(st, "type"),
  11. style_id = xml_attr(st, "styleId"),
  12. style_name = xml_attr(xml_child(st, "w:name"), "val"),
  13. based_on = xml_attr(xml_child(st, "w:basedOn"), "val"),
  14. next_style = xml_attr(xml_child(st, "w:next"), "val"),
  15. p_space_before = xml_attr(xml_find_first(st, "w:pPr/w:spacing"), "before"),
  16. p_space_after = xml_attr(xml_find_first(st, "w:pPr/w:spacing"), "after"),
  17. p_space_line = xml_attr(xml_find_first(st, "w:pPr/w:spacing"), "line"),
  18. p_space_linerule = xml_attr(xml_find_first(st, "w:pPr/w:spacing"), "lineRule"),
  19. p_ind_left = xml_attr(xml_find_first(st, "w:pPr/w:ind"), "left"),
  20. p_ind_right = xml_attr(xml_find_first(st, "w:pPr/w:ind"), "right"),
  21. p_ind_hanging = xml_attr(xml_find_first(st, "w:pPr/w:ind"), "hanging"),
  22. p_ind_firstLine = xml_attr(xml_find_first(st, "w:pPr/w:ind"), "firstLine")
  23. )
  24. }
  25. #' @importFrom stringi stri_c
  26. get_style_property <- function(docx, style_id, sub = c("", "pPr", "rPr"),
  27. el, attr = "val") {
  28. docx <- "custom-reference.docx"
  29. sxml <- read_xml(unz(docx, filename = "word/styles.xml"))
  30. xml_find_all(sxml, stri_c("/w:styles/w:style[@w:styleId=\"", style_id, "\"]"))
  31. }