hidden examples

This commit is contained in:
Rohit Tanwar
2018-01-21 15:08:00 +05:30
parent 418eb81d05
commit 94df622b5c
3 changed files with 122 additions and 43 deletions

View File

@ -9,6 +9,7 @@ for file in files:
fileData = someFile.read()
someFile.close()
originalCode = re.search(codeRe,fileData).group(0)
print(re.split(codeRe,fileData)[0])
formatedCode = autopep8.fix_code(re.split(codeRe,fileData)[1])
fileToSave = fileData.replace(originalCode,('```python \n'+formatedCode+'\n```'))
someFile = open("snippets/"+file,'w')

View File

@ -1,4 +1,6 @@
import os
import re
codeRe = "```\s*python([\s\S]*?)```"
def title_case(str):
return str[:1].upper() + str[1:].lower()
EMOJIS = {
@ -46,5 +48,6 @@ for category in tag_dict:
for snippet in tag_dict[category]:
someFile = open("snippets/" + snippet + '.md')
fileData = someFile.read()
toAppend += fileData + '\n'
codeParts = re.split(codeRe,fileData)
toAppend += codeParts[0] + f'```py{codeParts[1]} \n ```' +codeParts[2] + f'<details><summary>View Examples</summary>\n\n```py\n{codeParts[3]}\n```\n<details>' + '\n'
open("README.md",'w').write(start+toAppend+'\n'+end)