diff --git a/.coveragerc b/.coveragerc index 8c253ec..8190f9f 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,4 +1,9 @@ [report] exclude_lines = pragma: no cover - if TYPE_CHECKING: \ No newline at end of file + if TYPE_CHECKING: + def __.+__ + @overload + keys + values + items diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 0b909e3..1f8498f 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ["3.10"] + python-version: ["3.11"] steps: - uses: actions/checkout@v2 @@ -27,9 +27,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pytest-cov - pip install coverage - pip install . + pip install .[tests,markdown] - name: Run tests with coverage run: | make test diff --git a/COMLETED.md b/COMLETED.md deleted file mode 100644 index 5f62a0a..0000000 --- a/COMLETED.md +++ /dev/null @@ -1,116 +0,0 @@ -# TODO -- [x] Write Tests - - [x] Utils - - [x] find - - [x] misc - - [x] transform - - [x] travel - - [x] validate - - [x] AST - - [x] Correct AST Generation (parsing) - - [x] To json - - [x] To phml - - [x] To html - - [x] Correct ast conversion (compiling) - - [x] From phml/html - - [x] From json -- [x] All utilities - - [x] unist - - [x] hast -- [x] Ensure python conditions are immediate siblings -- [x] Optimize - - [x] Parsing files - - [x] Compiling files - - [x] AST linking from parser and compiler - - [x] Nodes to dataclasses? - - [x] Utilities -- [x] Component based system -- [x] Layout for components - - [x] Can provide script, python, styles elements - - [x] Parent element or single element and then script, style, python, etc? -- [x] re-write inspect to be external util function - - [x] Pretty lines - - [x] # children - - [x] Positional - - [x] Type and/or tag - - [x] values of literals - - [x] properties of elements - - [x] data of entire tree -- [x] from-python: create temp python file for `python` tag and evaluate and import all *`from temp_python import *`* -- [x] evaluate-python: evaluate a string containing python -- [x] Node conversion external from nodes -- [x] Validate ast is proper format - - [x] doctype is only in root - - [x] if no doctype add doctype - - [x] root nodes are at the root of the tree -- [x] Convert From Formats - - [x] Json - - [x] html - - [x] phml -- [x] Convert To Formats - - [x] Json - - [x] phml - - [x] html - -## Utils from [`unist`](https://github.com/syntax-tree/unist#list-of-utilities) and [`hast`](https://github.com/syntax-tree/hast#list-of-utilities) to implement - -### unist -- [x] position: Positional information on node -- [x] inspect: Node inspector -- [x] find: Find node by condition -- [x] find-after: Find first node after certain node -- [x] find-all-after: Find all nodes after certain node -- [x] size: Calc number of nodes in a tree -- [x] test: Check if node passes test -- [x] find-before: Find first node before certain node -- [x] find-all-before: Find all nodes before certain node -- [x] find-all-between: Find all nodes between two nodes -- [x] ancestor: Get common ancestor of one or more nodes - -- [x] walk: recursively walk over nodes -- [x] visit-children: visit direct children of a parent -- [x] visit-all-after: visit all nodes after another node - -- [x] filter: Create a new tree with only nodes that pass a condition -- [x] remove: Remove nodes from trees -- [x] map: Create a new tree by mapping nodes - -- [x] assert: Asserts that a node is valid -- [x] generated: Check if node is generated - -- [x] builder: Helper for creating ast's (Own module) -- [x] index: Index the tree given conditions. Helps with traversal -- [x] modify-children: modify direct children of a parent - -- [ ] ? replace-all-between: replace nodes between two nodes or positions -- [ ] ? reduce: recursively reduce tree -- [ ] ? flatmap: Flat version of tree -- [ ] ? flat-filter: flat map of `filter` -- [ ] ? source: get the source of a value - -## hast -- [x] class-list: Mimic browser's classList API -- [x] classnames: merge class names together -- [x] has-property: Check if element has a certain property -- [x] heading: check if node is a heading -- [x] heading-rank: get the rank(depth/level) of headings -- [x] is-css-link: check if node is a CSS link -- [x] is-css-style: check if node is a CSS style -- [x] is-element: check if node is a certain element -- [x] is-event-handler: check if property is an event handler -- [x] is-javascript: check if node is a javascript `script` [ref](https://html.spec.whatwg.org/#category-label) -- [x] shift-heading: change heading rank (depth/level) -- [x] find-and-replace: find and replace text in tree -- [x] to-string: Get textContent of element - -- [x] embedded: check if a node is an embedded element -- [x] interactive: check if the node is an interactive element -- [x] phrasing: check if node is phrasing content -- [ ] ? menu-state: check the state of a menu element - -- [x] select: `querySelector`, `querySelectorAll`, and `matches` -- [x] sanitize: sanitize nodes -- [ ] ? to-text: inner-text of element - Rendered text - -- [ ] ? to-markdown: Converts phml ast tree to markdown -- [ ] ? from-markdown: Uses python markdown and gets ast from rendered markdown diff --git a/README.md b/README.md index 51a894c..0ba4104 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,32 @@ - [](https://github.com/Tired-Fox/phml/blob/main/LICENSE) [](https://github.com/tired-fox/phml "Go to GitHub repo") -[](https://github.com/tired-fox/phml) -[](https://github.com/tired-fox/phml) - # Python Hypertext Markup Language (phml) -[](https://github.com/Tired-Fox/phml/actions/workflows/deploy_docs.yml) [](https://github.com/tired-fox/phml/releases/) -[](https://github.com/tired-fox/phml/issues)    - -**TOC** -- [Python Hypertext Markup Language (phml)](#python-hypertext-markup-language-phml) - - [Overview](#overview) - - [How to use](#how-to-use) - +
{{ message }}
`, which renders to, `Hello World!
`. -> Note: Inline python blocks are only rendered in a Text element or inside an html attribute. +> Note: Inline python blocks are only rendered in a Text element or inside an html attribute. Conditional rendering with `@if`, `@elif`, and `@else` is an extremely helpful tool in phml. `@if` can be used alone and the python inside it's value must be truthy for the element to be rendered. `@elif` requires an element with a `@if` or `@elif` attribute immediately before it, and it's condition is rendered the same as `@if` but only rendered if a `@if` or `@elif` first fails. `@else` requires there to be either a `@if` or a `@else` immediately before it. It only renders if the previous element's condition fails. If `@elif` or `@else` is on an element, but the previous element isn't a `@if` or `@elif` then an exception will occur. Most importantly, the first element in a chain of conditions must be a `@if`. @@ -89,34 +79,32 @@ The compiled html will be: ```htmlHello
-World
+Hello
+World
<> ``` @@ -150,11 +138,7 @@ Now how do you pass information to component to use in rendering? That is where ```html -{{ message }}
@@ -167,15 +151,11 @@ Props = { Both normal attribute values and python attributes can be used for props. The above example really only works for self closing components. What if you want to pass children to the component? That is where slots come in. ```html -{{ message }}
-Bottom
-Top
-Middle +Bottom
+Top
+ Middle