Comments (10)
in nodes.py create_node function, fixing the indentation for the following gets me a bit further:
if stripped_line == PYGMENTS_FILTER:
return PygmentsFilterNode(haml_line)
test code:
from hamlpy import hamlpy
haml = ":highlight\nprint 'hi'"
hamlParser = hamlpy.Compiler()
result = hamlParser.process(haml)
print result
<div class="highlight"><pre><span class="p">:</span><span class="n">highlight</span>
</pre></div>
print 'hi'
At the moment I'm a bit lost trying to grep the rest of the code to figure out why PygmentsFilterNode never has any internal_nodes, it only seems to have access to the highlight tag itself and not the content. I'm sure I'm missing something obvious.
from hamlpy.
Yep, my test code wasn't indented properly.
I think this works now...
from hamlpy import hamlpy
haml = ":highlight\n print 'hi'"
hamlParser = hamlpy.Compiler()
result = hamlParser.process(haml)
print result
class PygmentsFilterNode(FilterNode):
def render(self):
text = "".join((''.join((node.spaces, node.haml,'\n')) for node in self.internal_nodes))
output = highlight(text, guess_lexer(text), HtmlFormatter())
return output
<div class="highlight"><pre> <span class="n">print</span> <span class="s">'hi'</span>
</pre></div>
I'll play with it some more and submit a pull request tomorrow if I haven't overlooked anything obvious.
from hamlpy.
atm I can't figure out how to reconstruct the nodes so that the correct number of blank lines are preserved within the pre block, anyone have any hints?
Alternatively I would have thought there'd be a way to access the raw haml block prior to being stripped of whitespace but I can't find it.
from hamlpy.
Is the problem that it's not leaving line breaks after each line? Do you have any HAML example that demonstrates the problem
from hamlpy.
It's not preserving any blank lines within a pre. From my reading of the haml docs, they'd use :preserve or ~ to keep whitespace and line breaks within a tag but neither seem to be present in hamlpy.
%pre
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
%p Paragraph
<pre>
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
</pre>
<p>hi there</p>
from hamlpy.
Hey, just got a chance to look at this.
Blank lines are removed in nodes.py's create_node() with the lines:
if not stripped_line:
return None
Essentially this causes them not to be added to the list of nodes, which is why blank lines are removed from output.
You were saying that haml has :preserve and ~. Can you think of any reason why hamlpy should not preserve by default (I can't)? Preserving by default would be as simple as changing the above to
if not stripped_line:
return HamlNode(haml_line)
and fixing the four tests that fail due to the empty lines.
from hamlpy.
Preserve by default seems logical to me, can't think of a case where you'd want the opposite.
from hamlpy.
Had a proper look at this. This is trickier than it looks, if you have
%pre
Foo
(Blank line, no spaces)
Bar
If the blank line has no indentation HamlPy thinks it's the end of the <pre>
tag.
There are a few ways to fix this, but I'll have to do some more thinking to decide on the best way.
from hamlpy.
I've created a simple patch, that adds a pipe support (much like shpaml)
here's the commit:
https://github.com/czartur/HamlPy/commit/707d3c34870e19e0db0e872a5de474ebfee64ab4
and it works exactly like described here:
https://github.com/czartur/HamlPy/blob/master/reference.md#dropping-leading-whitespace
from hamlpy.
I've been too busy lately to have a proper look at this issue.
@czartur It seems a bit cumbersome to do it this way. Since the purpose of haml is to be easier than html, I wouldn't like to see something added that is more difficult to do than HTML.
There may be a simpler hack in hamlpy.py (where multi-line text is merged into one line) where we could append \n
's to a HamlNode.
Another possibility would be to get the indentation of a blank line to match the indentation of the previous line, which would solve the problem I mentioned previously. In practice this would require some refactoring in create_node
so that the previous node is passed in.
from hamlpy.
Related Issues (20)
- %a processing bug HOT 1
- jinja2 macro and call tags closed as blocks HOT 1
- HamlPy cannot run from library.zip HOT 3
- Python3 support for hamlpy HOT 10
- HamlPy comment before else produces incorrect output
- Not found on PyPi
- JS inline comments // don't work
- Reverse HTML to HamlPy compiler
- Can't find templatize HOT 2
- "or" statement does not work as expected in "if" tests
- Django if-else tags common inner content HOT 1
- support for :preserve tag?
- Load / extends html file
- HamlPy linter?
- Can't encode UTF8 characters in shell
- Quoting issues when using inline variable with filter
- Using a "with" statement does not close the tag properly HOT 2
- Hamlpy on django 1.11 uses the standard django-templates instead hamlpy HOT 2
- How to write an attribute starting with the symbol #
- A ReDoS vulnerability exists in nodes.py
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hamlpy.