citizenlabsgr / ballotpreview

Share how you plan to vote in Michigan.
https://share.michiganelections.io
GNU General Public License v3.0
1 stars 1 forks source link

Display lists as bullets #166

Closed jacebrowning closed 1 year ago

jacebrowning commented 1 year ago

On https://share.michiganelections.io/elections/49/precincts/1193/?share=all the - characters should be replaced with <li> tags.

knoxilla commented 1 year ago

The dashes all seem to be in the proposal descriptions, right? E.g.

 {
            "description": "This proposed constitutional amendment would:\n\n- Establish new individual right to reproductive freedom, including right to make and carry out all decisions about pregnancy, such as prenatal care, childbirth, postpartum care, contraception, sterilization, abortion, miscarriage management, and infertility\n- Allow state to regulate abortion after fetal viability, but not prohibit if medically needed to protect a patient’s life or physical or mental health\n- Forbid state discrimination in enforcement of this right; prohibit prosecution of an individual, or a person helping a pregnant individual, for exercising rights established by this amendment\n- Invalidate state laws conflicting with this amendment\n\nShould this proposal be adopted?",
            "district": {
                "category": "State",
                "id": 1427,
                "name": "Michigan",
                "url": "http://michiganelections.io/api/districts/1427/"
            },
            "election": {
                "active": true,
                "date": "2022-11-08",
                "date_humanized": "Tuesday, November 8th",
                "id": 49,
                "name": "State General",
                "reference_url": null,
                "url": "http://michiganelections.io/api/elections/49/"
            },
            "id": 8020,
            "name": "Proposal 22-3 A Proposal to Amend the State Constitution to Establish New Individual Right to Reproductive Freedom, Including Right to Make All Decisions About Pregnancy and Abortion; Allow State to Regulate Abortion in Some Cases; and Forbid Prosecution of Individuals Exercising Established Right",
            "reference_url": null,
            "url": "http://michiganelections.io/api/proposals/8020/"
        }

It looks like python-markdown will do a nice job on the state proposal exemplars we have in the current election:

>>> markdown.markdown(src1)
('<p>This proposed constitutional amendment would:</p>\n'
 '<ul>\n'
 '<li>Require members of legislature, governor, lieutenant governor, secretary '
 'of state, and attorney general file annual public financial disclosure '
 'reports after 2023, including assets, liabilities, income sources, future '
 'employment agreements, gifts, travel reimbursements, and positions held in '
 'organizations except religious, social, and political organizations</li>\n'
 '<li>Require legislature implement but not limit or restrict reporting '
 'requirements</li>\n'
 '<li>Replace current term limits for state representatives and state senators '
 'with a 12-year total limit in any combination between house and senate, '
 'except a person elected to senate in 2022 may be elected the number of times '
 'allowed when that person became a candidate</li>\n'
 '</ul>\n'
 '<p>Should this proposal be adopted?</p>')
>>> 
>>> markdown.markdown(src2)
('<p>This proposed constitutional amendment would:</p>\n'
 '<ul>\n'
 '<li>Establish new individual right to reproductive freedom, including right '
 'to make and carry out all decisions about pregnancy, such as prenatal care, '
 'childbirth, postpartum care, contraception, sterilization, abortion, '
 'miscarriage management, and infertility</li>\n'
 '<li>Allow state to regulate abortion after fetal viability, but not prohibit '
 'if medically needed to protect a patient’s life or physical or mental '
 'health</li>\n'
 '<li>Forbid state discrimination in enforcement of this right; prohibit '
 'prosecution of an individual, or a person helping a pregnant individual, for '
 'exercising rights established by this amendment</li>\n'
 '<li>Invalidate state laws conflicting with this amendment</li>\n'
 '</ul>\n'
 '<p>Should this proposal be adopted?</p>')
>>> 
>>> markdown.markdown(src3)
('<p>This proposed constitutional amendment would:</p>\n'
 '<ul>\n'
 '<li>Establish new individual right to reproductive freedom, including right '
 'to make and carry out all decisions about pregnancy, such as prenatal care, '
 'childbirth, postpartum care, contraception, sterilization, abortion, '
 'miscarriage management, and infertility</li>\n'
 '<li>Allow state to regulate abortion after fetal viability, but not prohibit '
 'if medically needed to protect a patient’s life or physical or mental '
 'health</li>\n'
 '<li>Forbid state discrimination in enforcement of this right; prohibit '
 'prosecution of an individual, or a person helping a pregnant individual, for '
 'exercising rights established by this amendment</li>\n'
 '<li>Invalidate state laws conflicting with this amendment</li>\n'
 '</ul>\n'
 '<p>Should this proposal be adopted?</p>')
>>> 

Once converted to html and rejoined into a single string, the proposal description html fragments could just be slotted into the page as-is, or wrapped in some div with appropriate class/style.

Question: Can we count on the provided descrs being markdownish enough for this to produce good results? Or would a more manual parsing be the better option?

knoxilla commented 1 year ago

Oops, pasted in the wrong conversion for the Prop 2 description. Here's what python-markdown would do to it:

>>> markdown.markdown(src2)
('<p>This proposed constitutional amendment would:</p>\n'
 '<ul>\n'
 '<li>Recognize fundamental right to vote without harassing conduct</li>\n'
 '<li>Require military or overseas ballots be counted if postmarked by '
 'election day</li>\n'
 '<li>Provide voter right to verify identity with photo ID or signed '
 'statement</li>\n'
 '<li>Provide voter right to single application to vote absentee in all '
 'elections</li>\n'
 '<li>Require state-funded absentee-ballot drop boxes, and postage for '
 'absentee applications and ballots</li>\n'
 '<li>Provide that only election officials may conduct post-election '
 'audits</li>\n'
 '<li>Require nine days of early in-person voting</li>\n'
 '<li>Allow donations to fund elections, which must be disclosed</li>\n'
 '<li>Require canvass boards certify election results based only on the '
 'official records of votes cast</li>\n'
 '</ul>\n'
 '<p>Should this proposal be adopted?</p>')
jacebrowning commented 1 year ago

Can we count on the provided descrs being markdownish enough for this to produce good results?

Yeah, I think so! The web scraping utilities in the Elections API essentially try to turn messy HTML into Markdown (sans styling).

knoxilla commented 1 year ago

Cool - I'll carry on. I am not a poetry whiz (more of a pipenv person) so I will try not to do too much violence to the project config when adding python-markdown !

jacebrowning commented 1 year ago

Thanks for your research on this! It looks like python-markdown does the trick: https://share.michiganelections.io/elections/49/precincts/1193/